List of usage examples for android.os ConditionVariable ConditionVariable
public ConditionVariable(boolean state)
From source file:com.jpassion.service_localservice_start_thread.LocalServiceInItsOwnThread.java
@Override public void onCreate() { mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); /// Start up the thread Thread notifyingThread = new Thread(null, mTask, "NotifyingService"); mCondition = new ConditionVariable(false); notifyingThread.start();//from w w w . j a v a 2s. com }
From source file:com.radicaldynamic.groupinform.services.InformOnlineService.java
@Override public void onCreate() { // Do some basic initialization for this service Collect.getInstance().setInformOnlineState(new InformOnlineState(getApplicationContext())); restoreSession();/* w ww . ja v a2s . c om*/ // connect() may not be run because of offline mode but metadata should still be loaded if available if (Collect.getInstance().getInformOnlineState().isOfflineModeEnabled()) { AccountDeviceList.loadDeviceList(); AccountFolderList.loadFolderList(); } Thread persistentConnectionThread = new Thread(null, mTask, "InformOnlineService"); mCondition = new ConditionVariable(false); persistentConnectionThread.start(); }
From source file:com.radicaldynamic.groupinform.services.DatabaseService.java
@Override public void onCreate() { Thread persistentConnectionThread = new Thread(null, mTask, "DatabaseService"); mCondition = new ConditionVariable(false); persistentConnectionThread.start();//from ww w. jav a 2 s.com }
From source file:com.facebook.FacebookActivityTestCase.java
protected void runOnBlockerThread(final Runnable runnable, boolean waitForCompletion) { Runnable runnableToPost = runnable; final ConditionVariable condition = waitForCompletion ? new ConditionVariable(!waitForCompletion) : null; if (waitForCompletion) { runnableToPost = new Runnable() { @Override// ww w. ja v a2s. co m public void run() { runnable.run(); condition.open(); } }; } TestBlocker blocker = getTestBlocker(); Handler handler = blocker.getHandler(); handler.post(runnableToPost); if (waitForCompletion) { boolean success = condition.block(10000); assertTrue(success); } }
From source file:gov.nasa.arc.geocam.geocam.GeoCamService.java
@Override public void onCreate() { Log.d(GeoCamMobile.DEBUG_ID, "GeoCamService::onCreate called"); super.onCreate(); // Prevent this service from being prematurely killed to reclaim memory buildNotification("GeoCam uploader starting...", "Starting..."); Reflect.Service.startForeground(this, NOTIFICATION_ID, mNotification); // Location Manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); registerListener();// w ww .j a va2 s .c o m mLocationManager.addGpsStatusListener(mGpsStatusListener); // Notification Manager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Upload queue and thread // Initialize with mCv open so we immediately try to upload when the thread is spawned // This is important on service restart with non-zero length queue // The thread will close mCv if the queue is empty mCv = new ConditionVariable(true); mIsUploading = new AtomicBoolean(false); mLastStatus = new AtomicInteger(0); if (mUploadQueue == null) { mUploadQueue = new GeoCamDbAdapter(this); mUploadQueue.open(); } if (mGpsLog == null) { mGpsLog = new GpsDbAdapter(this); mGpsLog.open(); } mPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { // wake up upload thread if upload was just enabled boolean isUploadEnabled = prefs.getBoolean(GeoCamMobile.SETTINGS_SERVER_UPLOAD_ENABLED, true); Log.d(GeoCamMobile.DEBUG_ID, "GeoCamService.mPrefListener.onSharedPreferenceChanged" + " key=" + key + " isUploadEnabled=" + Boolean.toString(isUploadEnabled)); if (key.equals(GeoCamMobile.SETTINGS_SERVER_UPLOAD_ENABLED) && isUploadEnabled) { Log.d(GeoCamMobile.DEBUG_ID, "GeoCamService.mPrefListener.onSharedPreferenceChanged" + " waking up upload thread"); mCv.open(); } } }; SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); settings.registerOnSharedPreferenceChangeListener(mPrefListener); mUploadThread = new Thread(null, uploadTask, "UploadThread"); mUploadThread.start(); }