Example usage for android.os HandlerThread start

List of usage examples for android.os HandlerThread start

Introduction

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

Prototype

public synchronized void start() 

Source Link

Document

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Usage

From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java

/**
 * Update the camera preview. {@link #startPreview()} needs to be called in advance.
 *//*from   ww w. j  a v a  2  s . co m*/
private void updatePreview() {
    if (null == mCameraDevice) {
        return;
    }
    try {
        setUpCaptureRequestBuilder(mPreviewBuilder);
        final HandlerThread thread = new HandlerThread("CameraPreview");
        thread.start();
        mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.owncloud.android.services.OperationsService.java

/**
 * Service initialization/*from  w  w w  .  j a  v  a2s.c  om*/
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");

    /// First worker thread for most of operations 
    HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
    mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);

    /// Separated worker thread for download of folders (WIP)
    thread = new HandlerThread("Syncfolder thread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mSyncFolderHandler = new SyncFolderHandler(thread.getLooper(), this);

    // create manager for local broadcasts
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
}

From source file:me.piebridge.prevent.ui.PreventActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    ThemeUtils.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from   w  ww .  j  a v a2 s.co  m
    ThemeUtils.fixSmartBar(this);

    mPager = (ViewPager) findViewById(R.id.pager);
    main = findViewById(R.id.main);
    actions = findViewById(R.id.actions);
    removeButton = (Button) findViewById(R.id.remove);
    preventButton = (Button) findViewById(R.id.prevent);
    removeButton.setOnClickListener(this);
    preventButton.setOnClickListener(this);
    preventButton.setEnabled(false);
    removeButton.setEnabled(false);
    receiver = new HookReceiver();

    mPageTitles = new String[] { getString(R.string.applications), getString(R.string.prevent_list) };
    mPageSelections = new ArrayList<Set<String>>();
    mPageSelections.add(new HashSet<String>());
    mPageSelections.add(new HashSet<String>());
    mPager.setOnPageChangeListener(this);
    mPager.setAdapter(new ScreenSlidePagerAdapter(getSupportFragmentManager()));

    HandlerThread thread = new HandlerThread("PreventUI");
    thread.start();
    mHandler = new Handler(thread.getLooper());

    try {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actions.setVisibility(View.GONE);
        }
    } catch (NoSuchMethodError e) { // NOSONAR
        // do nothing
    }

    try {
        Class<?> clazz = Class.forName("de.robv.android.xposed.XposedBridge", false,
                ClassLoader.getSystemClassLoader());
        Field field = clazz.getDeclaredField("disableHooks");
        field.setAccessible(true);
        field.set(null, true);
    } catch (ClassNotFoundException e) {
        UILog.d("cannot find Xposed", e);
    } catch (Throwable t) { // NOSONAR
        UILog.d("cannot disable Xposed", t);
    }

    if (!BuildConfig.RELEASE && TextUtils.isEmpty(LicenseUtils.getLicense(this))) {
        showTestDialog();
    } else {
        init();
    }
}

From source file:com.bitants.wally.fragments.SearchFragment.java

private void setupHandlers() {
    HandlerThread handlerThread = new HandlerThread("Search.background");
    handlerThread.start();
    backgroundHandler = new Handler(handlerThread.getLooper(), this);
    uiHandler = new Handler(getActivity().getMainLooper(), this);
}

From source file:com.android.wfds.printservice.WPrintService.java

@Override
public void onCreate() {
    mJNI = new WprintJNI();
    mServiceHandler = new ServiceHandler(this);
    mServiceMessenger = new Messenger(mServiceHandler);
    WPrintService.loadLibraries(getApplicationInfo());
    super.onCreate();
    HandlerThread jobThread = new HandlerThread(MobilePrintConstants.PRINT_SERVICE_JOB_THREAD_ID);
    jobThread.start();
    mJobHandler = new JobHandler(this, jobThread.getLooper(), mJNI);
    mJobHandler.sendEmptyMessage(MobilePrintConstants.WPRINT_SERVICE_MSG__INIT);
}

From source file:de.tubs.ibr.dtn.service.DaemonService.java

@Override
public void onCreate() {
    super.onCreate();

    // open statistic database
    mStatsDatabase = new StatsDatabase(this);
    mStatsLastAction = null;//from   w ww .  ja va2 s .  c o  m

    // create daemon main thread
    mDaemonProcess = new DaemonProcess(this, mProcessHandler);

    /*
     * incoming Intents will be processed by ServiceHandler and queued in
     * HandlerThread
     */
    HandlerThread thread = new HandlerThread("DaemonService_IntentThread");
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    // create a session manager
    mSessionManager = new SessionManager(this);

    // create P2P Manager
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mP2pManager = new P2pManager(this);
        mP2pManager.create();
    }

    // start initialization of the daemon process
    final Intent intent = new Intent(this, DaemonService.class);
    intent.setAction(de.tubs.ibr.dtn.service.DaemonService.ACTION_INITIALIZE);

    // queue the initialization job as the first job of the handler
    Message msg = mServiceHandler.obtainMessage();
    msg.arg1 = -1; // invalid startId (this never leads to a stop of the
                   // service)
    msg.obj = intent;
    mServiceHandler.sendMessage(msg);
}

From source file:com.digitalarx.android.files.services.FileUploader.java

/**
 * Service initialization/*  www . jav a2s. com*/
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileUploaderBinder();
}

From source file:com.example.alyshia.customsimplelauncher.MainActivity.java

public void setkioskReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(KioskMode.ACTION_ENABLE_KIOSK_MODE_RESULT);
    intentFilter.addAction(KioskMode.ACTION_DISABLE_KIOSK_MODE_RESULT);

    if (kioskReceiver == null) {
        kioskReceiver = new KioskReceiver(this, MainActivity.this);
        HandlerThread handlerThread = new HandlerThread("DifferentThread", Process.THREAD_PRIORITY_BACKGROUND);
        handlerThread.start();
        Looper looper = handlerThread.getLooper();
        kioskHandler = new Handler(looper, this);
        registerReceiver(kioskReceiver, intentFilter, null, kioskHandler);
    }//from w w  w. j  a v a  2s . c  o m

}

From source file:org.anhonesteffort.flock.MigrationService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("MigrationService", HandlerThread.NORM_PRIORITY);
    thread.start();

    Looper serviceLooper = thread.getLooper();

    serviceHandler = new ServiceHandler(serviceLooper);
    notifyManager = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(getBaseContext());

    try {//w w  w. j  ava  2 s  .  c  om

        Optional<DavAccount> account = DavAccountHelper.getAccount(getBaseContext());
        Optional<MasterCipher> masterCipher = KeyHelper.getMasterCipher(getBaseContext());

        if (account.isPresent() && masterCipher.isPresent()) {
            this.account = account.get();
            this.masterCipher = masterCipher.get();
        } else
            Log.e(TAG, "ACCOUNT NOT PRESENT xxx 0.O");

    } catch (IOException e) {
        Log.e(TAG, "exception while getting MasterCipher >> " + e);
    }
}

From source file:com.cerema.cloud2.files.services.FileUploader.java

/**
 * Service initialization//ww w. j a  v a  2 s .  c  o m
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileUploaderBinder();

    // add AccountsUpdatedListener
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addOnAccountsUpdatedListener(this, null, false);
}