Example usage for android.os HandlerThread HandlerThread

List of usage examples for android.os HandlerThread HandlerThread

Introduction

In this page you can find the example usage for android.os HandlerThread HandlerThread.

Prototype

public HandlerThread(String name, int priority) 

Source Link

Document

Constructs a HandlerThread.

Usage

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  .jav a 2 s  .c  om

    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: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();//from w  w  w  . ja va2 s.c  om

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mLocalBroadcastMgr = LocalBroadcastManager.getInstance(getApplicationContext());

    Locator.setDebug(true);
}

From source file:com.squareup.picasso3.Stats.java

Stats(PlatformLruCache cache) {
    this.cache = cache;
    this.statsThread = new HandlerThread(STATS_THREAD_NAME, THREAD_PRIORITY_BACKGROUND);
    this.statsThread.start();
    Utils.flushStackLocalLeaks(statsThread.getLooper());
    this.handler = new StatsHandler(statsThread.getLooper(), this);
}

From source file:com.amgems.uwschedule.services.LoginService.java

@Override
public void onCreate() {
    HandlerThread handlerThread = new HandlerThread("HANDLERTHREAD", Process.THREAD_PRIORITY_BACKGROUND);
    handlerThread.start();// w w w. jav  a 2s .  c om

    mServiceLooper = handlerThread.getLooper();
    mHandler = new LoginHandler(mServiceLooper);
}

From source file:org.durka.hallmonitor.CoreService.java

@Override
public void onCreate() {
    Log.d(LOG_TAG + ".oC", "Core service creating");
    localCoreService = this;

    mStateManager = ((CoreApp) getApplicationContext()).getStateManager();

    Log.d(LOG_TAG + ".oC", "Register special actions");
    mStateManager.registerCoreService(this);

    mStateManager.registerCoreReceiver();

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    HandlerThread thread = new HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();//from   w  ww.j  a v  a 2 s  . co  m

    // Get the HandlerThread's Looper and use it for our Handler
    mTouchCoverLooper = thread.getLooper();
    mTouchCoverHandler = new TouchCoverHandler(mTouchCoverLooper);
    lastTouchCoverRequest = mStateManager.getCoverClosed();

    try {
        startActivityAsUser = ((ContextWrapper) this).getClass().getMethod("startActivityAsUser", Intent.class,
                UserHandle.class);
        Log.d(LOG_TAG, "startActivityAsUser registred");
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    launchDefaultActivity = new Intent(localCoreService, DefaultActivity.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

    mUserHandle = android.os.Process.myUserHandle();
}

From source file:com.tenkiv.tekdaqc.android.services.CommunicationService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "CommunicationService onCreate()");

    // Setup the background thread and its controls
    HandlerThread thread = new HandlerThread("TekDAQC Communication Service",
            Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();//from   w  w w.  ja v  a 2 s .  c o m

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mLocalBroadcastMgr = LocalBroadcastManager.getInstance(getApplicationContext());

    // Initialize the session map
    mCommSessions = new ConcurrentHashMap<String, ASCIICommunicationSession>();
}

From source file:de.schildbach.wallet.ui.AlertDialogsFragment.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();//  www.  ja  va  2s  .  com
    backgroundHandler = new Handler(backgroundThread.getLooper());

    final PackageInfo packageInfo = application.packageInfo();
    final int versionNameSplit = packageInfo.versionName.indexOf('-');
    final HttpUrl.Builder url = HttpUrl
            .parse(Constants.VERSION_URL
                    + (versionNameSplit >= 0 ? packageInfo.versionName.substring(versionNameSplit) : ""))
            .newBuilder();
    url.addEncodedQueryParameter("package", packageInfo.packageName);
    url.addEncodedQueryParameter("installer",
            Strings.nullToEmpty(packageManager.getInstallerPackageName(packageInfo.packageName)));
    url.addQueryParameter("current", Integer.toString(packageInfo.versionCode));
    versionUrl = url.build();
}

From source file:com.cyanogenmod.eleven.provider.LocalizedStore.java

private LocalizedStore(final Context context) {
    mMusicDatabase = MusicDB.getInstance(context);
    mContext = context;//  w w w .  j ava 2  s.  c o  m
    mLocaleSetManager = new LocaleSetManager(mContext);

    mHandlerThread = new HandlerThread("LocalizedStoreWorker", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper()) {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == LOCALE_CHANGED && mLocaleSetManager.localeSetNeedsUpdate()) {
                rebuildLocaleData(mLocaleSetManager.getSystemLocaleSet());
            }
        }
    };

    // check to see if locale has changed
    onLocaleChanged();
}

From source file:org.peterbaldwin.vlcremote.sweep.PortSweeper.java

public PortSweeper(int port, String file, int threadCount, Callback callback, Looper looper) {
    mPort = port;/*from w w w  .  j a v  a 2  s . c om*/
    mPath = file;
    mWorkerCount = threadCount;
    mCallback = callback;

    mAddressQueue = new ConcurrentLinkedQueue<byte[]>();

    mWorkerManager = new MyWorkerManager();

    mWorkerCallback = new MyWorkerCallback();

    mScanThread = new HandlerThread("Scanner", Process.THREAD_PRIORITY_BACKGROUND);
    mScanThread.start();

    Handler.Callback callbackHandlerCallback = new MyCallbackHandlerCallback();
    mCallbackHandler = new Handler(looper, callbackHandlerCallback);

    Handler.Callback scanHandlerCallback = new MyScanHandlerCallback();
    mScanHandler = new Handler(mScanThread.getLooper(), scanHandlerCallback);
}

From source file:org.dvbviewer.controller.service.SyncService.java

@Override
public void onCreate() {
    Log.i(SyncService.class.getSimpleName(), "onCreate");
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    DVBViewerPreferences dvbPrefs = new DVBViewerPreferences(getApplication());
    prefs = dvbPrefs.getPrefs();/*ww  w .ja v a2s .c  om*/
    HandlerThread thread = new HandlerThread(SyncService.class.getName(), Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
}