Code example for HandlerThread

Methods: getLooper, start

0
    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, 
        // PicasaService.class).putExtras(extras)); 
    } 
 
    public PicasaService() { 
        super(); 
        mSyncThread.start();
        mSyncHandler = new Handler(mSyncThread.getLooper());
        mSyncHandler.post(new Runnable() {
            public void run() { 
                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            } 
        });