void resume(OnRefreshUiListener listener) { synchronized (mLock) { mResumed = true; mRefreshUiListener = listener; if (!mBackgroundHandler.hasMessages(MSG_UPDATE_CONTENTS)) { mBackgroundHandler.sendEmptyMessage(MSG_UPDATE_CONTENTS); } mHandler.sendEmptyMessage(MSG_UPDATE_TIME); } }
public void handleMessage(Message msg) { switch (msg.what) { case HANDLE_APPLICATION_QUIT_EVENT: // Close the application cleanly { Log.i(TAG, "mHandler.handleMessage(): APPLICATION_QUIT_EVENT"); mBackgroundHandler.leaveSession(); mBackgroundHandler.cancelAdvertise(); mBackgroundHandler.unbindSession(); mBackgroundHandler.releaseName(); mBackgroundHandler.exit(); stopSelf(); } break; case HANDLE_JOIN_SESSION_EVENT: // Synchronous join session { Log.i(TAG, "mHandler.handleMessage(): USE_JOIN_CHANNEL_EVENT"); mBackgroundHandler.joinSession(); } break; case HANDLE_LEAVE_SESSION_EVENT: // Gracefully close session { Log.i(TAG, "mHandler.handleMessage(): USE_LEAVE_CHANNEL_EVENT"); mBackgroundHandler.leaveSession(); } break; default: break; } }
private CrashRecoveryHandler(Controller controller) { mController = controller; mContext = mController.getActivity().getApplicationContext(); mForegroundHandler = new Handler(); mBackgroundHandler = new Handler(BackgroundHandler.getLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_WRITE_STATE: if (LOGV_ENABLED) { Log.v(LOGTAG, "Saving crash recovery state"); } Parcel p = Parcel.obtain(); try { Bundle state = (Bundle) msg.obj; state.writeToParcel(p, 0); File stateJournal = new File(mContext.getCacheDir(), STATE_FILE + ".journal"); FileOutputStream fout = new FileOutputStream(stateJournal); fout.write(p.marshall()); fout.close(); File stateFile = new File(mContext.getCacheDir(), STATE_FILE); if (!stateJournal.renameTo(stateFile)) { // Failed to rename, try deleting the existing // file and try again stateFile.delete(); stateJournal.renameTo(stateFile); } } catch (Throwable e) { Log.i(LOGTAG, "Failed to save persistent state", e); } finally { p.recycle(); } break; case MSG_CLEAR_STATE: if (LOGV_ENABLED) { Log.v(LOGTAG, "Clearing crash recovery state"); } File state = new File(mContext.getCacheDir(), STATE_FILE); if (state.exists()) { state.delete(); } break; case MSG_PRELOAD_STATE: mRecoveryState = loadCrashState(); synchronized (CrashRecoveryHandler.this) { mIsPreloading = false; mDidPreload = true; CrashRecoveryHandler.this.notifyAll(); } break; } } }; }
void resume(OnRefreshUiListener listener) { synchronized (mLock) { mResumed = true; mRefreshUiListener = listener; boolean usersChanged = mUmBroadcastReceiver.checkUsersChangedLocked(); boolean configChanged = mInterestingConfigChanges.applyNewConfig(mApplicationContext.getResources()); if (usersChanged || configChanged) { mHaveData = false; mBackgroundHandler.removeMessages(MSG_RESET_CONTENTS); mBackgroundHandler.removeMessages(MSG_UPDATE_CONTENTS); mBackgroundHandler.sendEmptyMessage(MSG_RESET_CONTENTS); } if (!mBackgroundHandler.hasMessages(MSG_UPDATE_CONTENTS)) { mBackgroundHandler.sendEmptyMessage(MSG_UPDATE_CONTENTS); } mHandler.sendEmptyMessage(MSG_UPDATE_TIME); } }
void updateNow() { synchronized (mLock) { mBackgroundHandler.removeMessages(MSG_UPDATE_CONTENTS); mBackgroundHandler.sendEmptyMessage(MSG_UPDATE_CONTENTS); } }
/** * When Android decides that our Service is no longer needed, we need to tear down the thread that * is servicing our long-lived remote operations. This method does so. */ private void stopBusThread() { mBackgroundHandler.exit(); }