List of usage examples for android.os HandlerThread getLooper
public Looper getLooper()
From source file:Main.java
/** * Get a Handler that is running on a background thread. * NOTE!!! The HandlerThread that is passed as a param MUST be stopped via * handlerThread.quitSafely() or handlerThread.quit(); * @param handlerThread {@link HandlerThread}Cannot be null since this will start * the thread when it is passed. * @return {@link Handler}//from w ww.ja va 2s.co m */ public static Handler getBackgroundHandler(@NonNull HandlerThread handlerThread) { handlerThread.start(); Handler handler = new Handler(handlerThread.getLooper()); return handler; }
From source file:com.owncloud.android.ui.notifications.NotificationUtils.java
public static void cancelWithDelay(final NotificationManager notificationManager, final int notificationId, long delayInMillis) { HandlerThread thread = new HandlerThread( "NotificationDelayerThread_" + (new Random(System.currentTimeMillis())).nextInt(), Process.THREAD_PRIORITY_BACKGROUND); thread.start();// w w w . j ava 2s . c o m Handler handler = new Handler(thread.getLooper()); handler.postDelayed(new Runnable() { public void run() { notificationManager.cancel(notificationId); ((HandlerThread) Thread.currentThread()).getLooper().quit(); } }, delayInMillis); }
From source file:org.sufficientlysecure.keychain.service.PassphraseCacheService.java
/** * Gets a cached passphrase from memory by sending an intent to the service. This method is * designed to wait until the service returns the passphrase. * * @param context//from w w w . j ava2 s . c om * @param keyId * @return passphrase or null (if no passphrase is cached for this keyId) */ public static String getCachedPassphrase(Context context, long keyId) { Log.d(TAG, "getCachedPassphrase() get masterKeyId for " + keyId); Intent intent = new Intent(context, PassphraseCacheService.class); intent.setAction(ACTION_PASSPHRASE_CACHE_GET); final Object mutex = new Object(); final Bundle returnBundle = new Bundle(); HandlerThread handlerThread = new HandlerThread("getPassphraseThread"); handlerThread.start(); Handler returnHandler = new Handler(handlerThread.getLooper()) { @Override public void handleMessage(Message message) { if (message.obj != null) { String passphrase = ((Bundle) message.obj).getString(EXTRA_PASSPHRASE); returnBundle.putString(EXTRA_PASSPHRASE, passphrase); } synchronized (mutex) { mutex.notify(); } // quit handlerThread getLooper().quit(); } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); intent.putExtra(EXTRA_KEY_ID, keyId); intent.putExtra(EXTRA_MESSENGER, messenger); // send intent to this service context.startService(intent); // Wait on mutex until passphrase is returned to handlerThread synchronized (mutex) { try { mutex.wait(3000); } catch (InterruptedException e) { } } if (returnBundle.containsKey(EXTRA_PASSPHRASE)) { return returnBundle.getString(EXTRA_PASSPHRASE); } else { return null; } }
From source file:com.musenkishi.wally.util.PaletteLoader.java
private static void setupHandlers(Context context) { HandlerThread handlerThread = new HandlerThread("palette-loader-background"); handlerThread.start();//ww w . j av a2 s. c om backgroundHandler = new Handler(handlerThread.getLooper(), sCallback); uiHandler = new Handler(context.getMainLooper(), sCallback); }
From source file:com.musenkishi.atelier.Atelier.java
private static void setupHandlers(Context context) { HandlerThread handlerThread = new HandlerThread("palette-loader-background"); handlerThread.start();//from w w w. j av a 2 s .com backgroundHandler = new Handler(handlerThread.getLooper(), callback); uiHandler = new Handler(context.getMainLooper(), callback); }
From source file:com.wbtech.ums.UmsAgent.java
public static void onEvent(Context context, String event_id, int acc) { if (handler == null) { HandlerThread localHandlerThread = new HandlerThread("UmsAgent"); localHandlerThread.start();/*from w ww . ja v a 2s.co m*/ handler = new Handler(localHandlerThread.getLooper()); } EventController.postEventInfo(handler, context, new PostObjEvent(event_id, null, acc + "", context)); }
From source file:org.linkdroid.WebhookPostService.java
@Override public void onCreate() { LogsService.logSystemDebugMessage(this, getString(R.string.webhook_post_service_creating)); HandlerThread thread = new HandlerThread(TAG); thread.start();// w ww . j av a2 s.c o m serviceLooper = thread.getLooper(); serviceHandler = new ServiceHandler(serviceLooper); }
From source file:com.amgems.uwschedule.services.LoginService.java
@Override public void onCreate() { HandlerThread handlerThread = new HandlerThread("HANDLERTHREAD", Process.THREAD_PRIORITY_BACKGROUND); handlerThread.start();//from w w w .ja v a 2s.c om mServiceLooper = handlerThread.getLooper(); mHandler = new LoginHandler(mServiceLooper); }
From source file:de.persoapp.android.activity.fragment.ProgressFragment.java
public ProgressFragment() { setArguments(new Bundle()); HandlerThread handlerThread = new HandlerThread("progressAnimator"); handlerThread.start();//from w w w .j av a 2 s. co m mHandler = new MyHandler(handlerThread.getLooper()); }
From source file:com.tenkiv.tekdaqc.android.services.DiscoveryService.java
@Override public void onCreate() { super.onCreate(); HandlerThread thread = new HandlerThread("TekDAQC Discovery Service", Process.THREAD_PRIORITY_BACKGROUND); thread.start();// ww w. j a v a2s. c om mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, this); mLocalBroadcastMgr = LocalBroadcastManager.getInstance(getApplicationContext()); Locator.setDebug(true); }