Android HandlerThread - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HandlerThread class.

This code example shows how to use the following methods: getLooper, start
        mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        final boolean connected = mStorageManager.isUsbMassStorageConnected();
        if (DEBUG) Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)",
                mUmsAvailable, Environment.getExternalStorageState()));
         
        HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
        thr.start();
        mAsyncEventHandler = new Handler(thr.getLooper());
 
        onUsbMassStorageConnectionChanged(connected);
    } 
 
    /* 
     * @override com.android.os.storage.StorageEventListener 
     */ 
    @Override 
    public void onUsbMassStorageConnectionChanged(final boolean connected) {
        mAsyncEventHandler.post(new Runnable() {
            @Override 
            public void run() { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: start
	/** 
	 * This method initializes the aysnc screenshot saving logic 
	 */ 
	private void initScreenShotSaver() { 
		if(screenShotSaverThread == null || screenShotSaver == null) {
			screenShotSaverThread = new HandlerThread("ScreenShotSaver");
			screenShotSaverThread.start();
			screenShotSaver = new ScreenShotSaver(screenShotSaverThread);
		} 
	} 
 
	/**  
	 * This is the thread which causes a screenshot sequence to happen 
	 * in parallel with testing. 
	 */ 
	private class ScreenshotSequenceThread extends Thread {
		private int seqno = 0;
 
		private String name;
		private int quality;
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
 * Helper class for managing the background thread used to perform io operations 
 * and handle async broadcasts. 
 */ 
public final class AsyncHandler { 
 
    private static final HandlerThread sHandlerThread = new HandlerThread("AsyncHandler");
 
    private static final Handler sHandler;
 
    static { 
        sHandlerThread.start();
        sHandler = new Handler(sHandlerThread.getLooper());
    } 
 
    /* This class is never initiated */ 
    private AsyncHandler() { 
    } 
 
    /** 
     * @param r The {@link Runnable} to execute. 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
            handler = null;
        } 
    } 
 
    public void start() { 
        handlerThread = new HandlerThread("TDListenerHandlerThread");
        handlerThread.start();
        Looper looper = handlerThread.getLooper();
        handler = new Handler(looper);
        thread = new Thread(this);
        thread.start();
    } 
 
    public void stop() { 
        httpServer.notifyStop();
    } 
 
    public void onServerThread(Runnable r) {
        handler.post(r);
    } 
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
    private static Handler sWorkerQueue;
    private static WeatherDataProviderObserver sDataObserver;
 
    public WeatherWidgetProvider() { 
        // Start the worker thread 
        sWorkerThread = new HandlerThread("WeatherWidgetProvider-worker");
        sWorkerThread.start();
        sWorkerQueue = new Handler(sWorkerThread.getLooper());
    } 
 
    @Override 
    public void onEnabled(Context context) {
        // Register for external updates to the data to trigger an update of the widget.  When using 
        // content providers, the data is often updated via a background service, or in response to 
        // user interaction in the main app.  To ensure that the widget always reflects the current 
        // state of the data, we must listen for changes and update ourselves accordingly. 
        final ContentResolver r = context.getContentResolver();
        if (sDataObserver == null) {
            final AppWidgetManager mgr = AppWidgetManager.getInstance(context);
            final ComponentName cn = new ComponentName(context, WeatherWidgetProvider.class);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
 * a complete, successful download will open the file. 
 */ 
public class OpenDownloadReceiver extends BroadcastReceiver {
    private static Handler sAsyncHandler;
    static { 
        HandlerThread thr = new HandlerThread("Open browser download async");
        thr.start();
        sAsyncHandler = new Handler(thr.getLooper());
    } 
    @Override 
    public void onReceive(final Context context, Intent intent) {
        String action = intent.getAction();
        if (!DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
            openDownloadsPage(context);
            return; 
        } 
        long ids[] = intent.getLongArrayExtra(
                DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids == null || ids.length == 0) {
            openDownloadsPage(context);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
	public void onCreate() { 
		// TODO: It would be nice to have an option to hold a partial wakelock 
		// during processing, and to have a static startService(Context, Intent) 
		// method that would launch the service & hand off a wakelock. 
		super.onCreate(); 
		HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
		thread.start();
 
		mServiceLooper = thread.getLooper();
		mServiceHandler = new IntentServiceHandler(mServiceLooper, this);
	} 
 
	@Override 
	public void onStart(Intent intent, int startId) {
		Message msg = mServiceHandler.obtainMessage();
		msg.arg1 = startId;
		msg.arg2 = 0;
		msg.obj = intent;
		mServiceHandler.sendMessage(msg);
	} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
                ThreadedCursorAdapter.this.notifyDataSetInvalidated();
            } 
 
        }; 
        mSize = mCursorAdapter.getCount();
        HandlerThread thread = new HandlerThread("threaded_adapter_" + this,
                Process.THREAD_PRIORITY_BACKGROUND);
        thread.start();
        mLoadHandler = new Handler(thread.getLooper()) {
            @SuppressWarnings("unchecked") 
            @Override 
            public void handleMessage(Message msg) {
                if (DEBUG) {
                    Log.d(LOGTAG, "loading: " + msg.what);
                } 
                loadRowObject(msg.what, (LoadContainer) msg.obj);
            } 
        }; 
        mHandler = new Handler() {
            @Override 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
    public static final String KEY_ID = "com.cooliris.SYNC_ID";
    public static final int TYPE_USERS = 0;
    public static final int TYPE_USERS_ALBUMS = 1;
    public static final int TYPE_ALBUM_PHOTOS = 2;
 
    private final HandlerThread mSyncThread = new HandlerThread("PicasaSyncThread");
    private final Handler mSyncHandler;
    private static final AtomicBoolean sSyncPending = new AtomicBoolean(false);
 
    public static void requestSync(Context context, int type, long id) {
        Bundle extras = new Bundle();
        extras.putInt(KEY_TYPE, type);
        extras.putLong(KEY_ID, id);
 
        Account[] accounts = PicasaApi.getAccounts(context);
        for (Account account : accounts) {
            ContentResolver.requestSync(account, PicasaContentProvider.AUTHORITY, extras);
        } 
 
        // context.startService(new Intent(context, 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLooper, start
	 * @param name 
	 *            线程名字。 
	 * @return 在新线程运行的Handler对象。 
	 */ 
	public static Handler newHandlerInOtherThread(String name) {
		HandlerThread thread = new HandlerThread(name);
		thread.start();
		return new Handler(thread.getLooper());
	} 
 
	/** 
	 * 获取在新线程中运行的Looper对象。 
	 *  
	 * @param name 
	 *            线程名字。 
	 * @return 在新线程中运行的Looper对象。 
	 */ 
	public static Looper newHandlerLooperInOtherThread(String name) {
		HandlerThread thread = new HandlerThread(name);
		thread.start();
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android HandlerThread Questions & Answers:

See Code Examples for Android HandlerThread Methods: