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:de.persoapp.android.activity.fragment.ProgressFragment.java

public ProgressFragment() {
    setArguments(new Bundle());

    HandlerThread handlerThread = new HandlerThread("progressAnimator");
    handlerThread.start();
    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();

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

    Locator.setDebug(true);//from  w  ww . j  av a 2s. c om
}

From source file:com.binoy.vibhinna.CustomIntentService.java

@Override
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 ServiceHandler(mServiceLooper);
}

From source file:fr.enseirb.odroidx.videomanager.Uploader.java

public void onCreate() {
    Log.i(getClass().getSimpleName(), "Uploader on create");
    HandlerThread thread = new HandlerThread("Uploader");
    thread.start();

    mUploadLooper = thread.getLooper();//from   w  w  w  . java2  s.  c om
    mUploadHandler = new ServiceHandler(mUploadLooper);
}

From source file:org.peercast.pecaport.PecaPortService.java

@Override
public void onCreate() {
    super.onCreate();
    logger.info(getString(R.string.t_log_starting) + "PecaPortService");

    HandlerThread thread = new HandlerThread(TAG);
    thread.start();

    mServiceHandler = new ServiceHandler(thread.getLooper());
    mUiThreadHandler = new Handler(Looper.getMainLooper());
    mRouterDiscoverer = new RouterDiscoverer(getApplicationContext(), this);

    NetworkDeviceManager nicManager = NetworkDeviceManager.from(this);
    mActiveNicInfo = nicManager.getActiveInterface();
}

From source file:com.example.android.downloadablefonts.MainActivity.java

private Handler getHandlerThreadHandler() {
    if (mHandler == null) {
        HandlerThread handlerThread = new HandlerThread("fonts");
        handlerThread.start();
        mHandler = new Handler(handlerThread.getLooper());
    }/*from  ww  w .j a va 2  s  .  c o  m*/
    return mHandler;
}

From source file:com.kogitune.launcher3.LauncherAppWidgetHostView.java

@Override
public void updateAppWidget(RemoteViews remoteViews) {
    if (EXPERIMENTAL) {
        if (remoteViews != null) {
            Handler mH = null;//  w ww . ja va  2s.  c  om
            Field queueField = null;
            MessageQueue messageQueue = null;
            try {
                Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
                Class[] params = new Class[0];
                Method currentActivityThread = activityThreadClass.getDeclaredMethod("currentActivityThread",
                        params);
                Boolean accessible = currentActivityThread.isAccessible();
                currentActivityThread.setAccessible(true);
                Object obj = currentActivityThread.invoke(activityThreadClass);
                if (obj == null) {
                    Log.d("ERROR", "The current activity thread is null!");
                }
                currentActivityThread.setAccessible(accessible);

                Field mHField = activityThreadClass.getDeclaredField("mH");
                mHField.setAccessible(true);
                mH = (Handler) mHField.get(obj);
                queueField = Handler.class.getDeclaredField("mQueue");
                queueField.setAccessible(true);
                messageQueue = (MessageQueue) queueField.get(mH);

                HandlerThread handlerThread = new HandlerThread("other");
                handlerThread.start();
                handlerThread.quit();
                queueField.set(mH, null);

            } catch (Exception e) {
                Log.d("ERROR", Log.getStackTraceString(e));
            }
            Context context = getContext().getApplicationContext();
            NotificationManager notificationManager = (NotificationManager) context.getApplicationContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContent(remoteViews).setSmallIcon(R.drawable.ic_launcher_info_normal_holo)
                    .setContentTitle("My notification") // ?
                    .setContentText("Hello Notification!!"); // ?

            Notification notification = builder.build();
            notificationManager.notify(getAppWidgetId(), notification);

            final Field finalQueueField = queueField;
            final Handler finalMH = mH;
            final MessageQueue finalMessageQueue = messageQueue;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(50L);
                        if (finalMessageQueue != null)
                            finalQueueField.set(finalMH, finalMessageQueue);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }
    }
    // Store the orientation in which the widget was inflated
    mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
    super.updateAppWidget(remoteViews);
}

From source file:MainActivity.java

private void startPreview(CameraCaptureSession session) {
    mCameraCaptureSession = session;/*www .  j  av  a2 s  .  c  o  m*/
    mCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    HandlerThread backgroundThread = new HandlerThread("CameraPreview");
    backgroundThread.start();
    Handler backgroundHandler = new Handler(backgroundThread.getLooper());
    try {
        mCameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(), null, backgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.snt.bt.recon.services.BcScanService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //leave cpu on
    wl = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "wlTag2");
    wl.acquire();/*  ww w.j a  v a2s . co  m*/

    HandlerThread handlerThread = new HandlerThread("ht");
    handlerThread.start();
    Looper looper = handlerThread.getLooper();
    handler = new Handler(looper);

    //show notification
    showNotification();

    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_START_SCAN.equals(action)) {
            //final String param1 = intent.getStringExtra(EXTRA_LAT);
            sessionId = UUID.fromString(intent.getStringExtra(EXTRA_SID));
            handleActionStartScan();

        }
    }
    return START_STICKY;
}

From source file:paulscode.android.mupen64plusae.task.ExtractTexturesService.java

@Override
public void onCreate() {
    // Start up the thread running the service.  Note that we create a
    // separate thread because the service normally runs in the process's
    // main thread, which we don't want to block.  We also make it
    // background priority so CPU-intensive work will not disrupt our UI.
    HandlerThread thread = new HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();

    // Get the HandlerThread's Looper and use it for our Handler
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    //Show the notification
    Intent notificationIntent = new Intent(this, GalleryActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setContentTitle(getString(R.string.pathHiResTexturesTask_title))
            .setContentText(getString(R.string.toast_pleaseWait)).setContentIntent(pendingIntent);
    startForeground(ONGOING_NOTIFICATION_ID, builder.build());
}