@Override public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_GET_USERINFO_COMPLATE: mUserInfo = mUserService.getUserInfo(mUserid); if (mUserInfo == null) { // 如果没有找到这个userInfo,就发送错误消息 mMsgHandler.obtainMessage(BaseService.MSG_ERROR).sendToTarget(); return true; } updateUserInfo(); break; case UserService.MSG_SYNC_USERINFO_SUCCESS: case UserService.MSG_SYNC_USERINFO_FAILD: mMsgHandler.obtainMessage(MSG_GET_USERINFO_COMPLATE).sendToTarget(); break; case BaseService.MSG_ERROR: // 当没有网络的时候允许 if (msg.obj != null && msg.obj instanceof NoConnectionError) { mMsgHandler.obtainMessage(MSG_GET_USERINFO_COMPLATE).sendToTarget(); break; } // TODO 发生错误! showToast(getString(R.string.personalinfo_get_userinfo_faild)); finish(); break; case UserService.MSG_UPDATE_USERINFO_FAILD: showToast(R.string.personalinfo_update_faild); break; default: break; } return true; }
private void handleIntent(Intent intent) { mUserid = intent.getStringExtra(KEY_USERID); if (mUserid == null) { throw new IllegalArgumentException("Extra KEY_USERID is null"); } // 先加载UserInfo mUserInfo = mUserService.getUserInfo(mUserid); if (mUserInfo == null) { mUserService.syncUserInfo(mUserid, mMsgHandler); } else { updateUserInfo(); mUserService.syncUserInfo(mUserid, new Handler()); } }