Example usage for android.os HandlerThread getLooper

List of usage examples for android.os HandlerThread getLooper

Introduction

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

Prototype

public Looper getLooper() 

Source Link

Document

This method returns the Looper associated with this thread.

Usage

From source file:com.unlp.tesis.steer.LocationService.java

@Override
public void onCreate() {
    //GEOFENCES//w  w  w.ja  v  a2  s. c  om
    // Empty list for storing geofences.

    mGeofenceList = new ArrayList<Geofence>();
    // Initially set the PendingIntent used in addGeofences() and removeGeofences() to null.
    mGeofencePendingIntent = null;
    // Get the geofences used. Geofence data is hard coded in this sample.
    //Get Firebase database instance
    mDatabase = FirebaseDatabase.getInstance().getReference();
    populateGeofenceList();

    if (mGoogleApiClient == null) {

        mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    }
    mGoogleApiClient.connect();
    createLocationRequest();
    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    mServiceHandler = new Handler(handlerThread.getLooper());
}

From source file:com.hang.exoplayer.PlayService.java

@Override
public void onCreate() {
    super.onCreate();
    mAm = (AudioManager) getSystemService(AUDIO_SERVICE);
    playStatusReceiver = new PlayStatusReceiver();
    networkStateReceiver = new NetworkStateReceiver();
    IntentFilter netFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
    registerReceiver(networkStateReceiver, netFilter);
    IntentFilter intentFilter = new IntentFilter(SimplePlayer.ACTION_PLAY_STUTUS);
    LocalBroadcastManager.getInstance(this).registerReceiver(playStatusReceiver, intentFilter);
    Log.d(TAG, "registerReceiver");

    HandlerThread playThread = new HandlerThread("exoplayer");
    playThread.start();//w ww .j a  v  a  2 s .  c om
    playHandler = new PlayHandler(playThread.getLooper());
}

From source file:com.flipkart.batchdemo.MainActivity.java

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

    setContentView(R.layout.activity_main);

    HandlerThread handlerThread = new HandlerThread("bg");
    handlerThread.start();/*w ww .j  a  v  a 2 s  . c o  m*/
    Handler backgroundHandler = new Handler(handlerThread.getLooper());

    GsonSerializationStrategy<CustomTagData, SizeBatch<CustomTagData>> serializationStrategy = new GsonSerializationStrategy<>(
            new CustomTagDataAdapter(), null);

    debugTag = new Tag(DEBUG_LOGGER_GROUPID);
    perfTag = new Tag(PERF_LOGGER_GROUPID);
    dgTag = new Tag(DG_LOGGER_GROUPID);

    final NetworkPersistedBatchReadyListener perfListener = new NetworkPersistedBatchReadyListener(
            getApplicationContext(), getCacheDir() + "/" + "perf", serializationStrategy, backgroundHandler,
            new NetworkPersistedBatchReadyListener.NetworkBatchListener() {
                @Override
                public void performNetworkRequest(Batch batch, ValueCallback callback) {

                }
            }, 5, 100, 90, TRIM_MEMORY_BACKGROUND, new TrimmedBatchCallback() {
                @Override
                public void onTrimmed(int oldSize, int newSize) {

                }
            });

    perfListener.setListener(new PersistedBatchCallback() {
        @Override
        public void onPersistFailure(Batch batch, Exception e) {

        }

        @Override
        public void onPersistSuccess(Batch batch) {
            //SystemClock.sleep(2000);
            perfListener.finish(batch);
            Log.e("Perf", "Finish Called");
            ArrayList<CustomTagData> dataArrayList = (ArrayList<CustomTagData>) batch.getDataCollection();
            for (CustomTagData data : dataArrayList) {
                Log.e("OUT", data.getEvent().toString());
            }
        }

        @Override
        public void onFinish() {

        }
    });

    final NetworkPersistedBatchReadyListener debugListener = new NetworkPersistedBatchReadyListener(
            getApplicationContext(), getCacheDir() + "/" + "debug", serializationStrategy, backgroundHandler,
            new NetworkPersistedBatchReadyListener.NetworkBatchListener() {
                @Override
                public void performNetworkRequest(Batch batch, ValueCallback callback) {

                }
            }, 5, 100, 90, TRIM_MEMORY_BACKGROUND, new TrimmedBatchCallback() {
                @Override
                public void onTrimmed(int oldSize, int newSize) {

                }
            });

    debugListener.setListener(new PersistedBatchCallback<TagBatch<TagData>>() {
        @Override
        public void onPersistFailure(TagBatch<TagData> batch, Exception e) {

        }

        @Override
        public void onPersistSuccess(TagBatch<TagData> batch) {
            // SystemClock.sleep(2000);
            debugListener.finish(batch);
            Log.e("Debug", "Finish Called");
        }

        @Override
        public void onFinish() {

        }
    });

    final NetworkPersistedBatchReadyListener dgListener = new NetworkPersistedBatchReadyListener(
            getApplicationContext(), getCacheDir() + "/" + "dg", serializationStrategy, backgroundHandler,
            new NetworkPersistedBatchReadyListener.NetworkBatchListener() {
                @Override
                public void performNetworkRequest(Batch batch, ValueCallback callback) {

                }
            }, 5, 100, 90, TRIM_MEMORY_BACKGROUND, new TrimmedBatchCallback() {
                @Override
                public void onTrimmed(int oldSize, int newSize) {

                }
            });

    dgListener.setListener(new PersistedBatchCallback<TagBatch<TagData>>() {
        @Override
        public void onPersistFailure(TagBatch<TagData> batch, Exception e) {

        }

        @Override
        public void onPersistSuccess(TagBatch<TagData> batch) {
            //SystemClock.sleep(2000);
            dgListener.finish(batch);
            Log.e("Dg", "Finish Called");
        }

        @Override
        public void onFinish() {

        }
    });

    batchManager = new TagBatchManager.Builder<>().setSerializationStrategy(serializationStrategy)
            .setHandler(backgroundHandler)
            .addTag(perfTag,
                    new SizeBatchingStrategy(3,
                            new TapePersistenceStrategy(getCacheDir() + "/perf1", serializationStrategy)),
                    perfListener)
            .addTag(debugTag,
                    new SizeBatchingStrategy(3,
                            new TapePersistenceStrategy(getCacheDir() + "/debug1", serializationStrategy)),
                    debugListener)
            .addTag(dgTag,
                    new SizeBatchingStrategy(3,
                            new TapePersistenceStrategy(getCacheDir() + "/dg1", serializationStrategy)),
                    dgListener)
            .build(getApplicationContext());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.e("IN", TrackingHelper.getProductPageViewEvent(String.valueOf(count), "dfg", "fgh").toString());
            batchManager.addToBatch(Collections.singleton(new CustomTagData(perfTag,
                    TrackingHelper.getProductPageViewEvent(String.valueOf(count), "dfg", "fgh"))));
            Snackbar.make(view, "Replace with your own action " + count, Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
            count++;
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

From source file:eu.faircode.netguard.SinkholeService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "Create");

    HandlerThread thread = new HandlerThread(getString(R.string.app_name));
    thread.start();//w w  w  .j  a va2  s.  c om

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    // Listen for interactive state changes
    IntentFilter ifInteractive = new IntentFilter();
    ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
    ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(interactiveStateReceiver, ifInteractive);

    // Listen for connectivity updates
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);

    // Listen for added applications
    IntentFilter ifPackage = new IntentFilter();
    ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
    ifPackage.addDataScheme("package");
    registerReceiver(packageAddedReceiver, ifPackage);
}

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

private void setupHandlers() {
    HandlerThread handlerThread = new HandlerThread("Toplist.background");
    handlerThread.start();//from ww  w . j  a  v  a 2  s  .c  o m
    backgroundHandler = new Handler(handlerThread.getLooper(), this);
    uiHandler = new Handler(getActivity().getMainLooper(), this);
}

From source file:grupo19.locmess19.Services.LocationUpdatesService.java

@SuppressLint("WifiManagerLeak")
@Override// ww w.  j a v a 2  s  .c om
public void onCreate() {

    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    mGoogleApiClient.connect();
    createLocationRequest();

    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    mServiceHandler = new Handler(handlerThread.getLooper());
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    server = new ServerCommunication("10.0.2.2", 11113);
}

From source file:zuo.biao.library.base.BaseFragmentActivity.java

/**?
 * @param threadName/*from  w w  w  .j a  v  a 2 s .  c  o  m*/
 * @param runnable
 * @return
 */
public Handler runThread(String threadName, Runnable runnable) {
    if (runnable == null) {
        Log.e(TAG, "runThread  runnable == null >> return");
        return null;
    }
    HandlerThread handlerThread = new HandlerThread("" + threadName);
    handlerThread.start();//HandlerThread?
    Handler handler = new Handler(handlerThread.getLooper());//HandlerThreadlooperHandler
    handler.post(runnable);//postHandler

    handlerList.add(handler);
    runnableList.add(runnable);

    return handler;
}

From source file:io.clh.lrt.androidservice.TraceListenerService.java

@Override
public void onCreate() {
    Log.i(TAG, "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");
    thread.start();//from  www .j a  v  a 2  s .  c  o  m

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

    restClient = new DefaultHttpClient();

    //network on main thread H@XXX
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // Register the LRT receiver
    IntentFilter filter = new IntentFilter(ACTION_LRT_START);
    registerReceiver(mLrtReceiver, filter);
    filter = new IntentFilter(ACTION_LRT_TRACE);
    registerReceiver(mLrtReceiver, filter);
    filter = new IntentFilter(ACTION_LRT_STOP);
    registerReceiver(mLrtReceiver, filter);

    setNotification("LRT Tracing Service Running", true);

    infiLoop();
}

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();/*from w  ww. java2  s  . c  o m*/
    HandlerThread thread = new HandlerThread(SyncService.class.getName(), Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
}

From source file:com.twp.music.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Logger.i(TAG, "onCreate ---- ");
    setContentView(R.layout.activity_main);
    fm = getFragmentManager();//  ww  w. j a  va  2s . co m
    initView();
    token = MusicUtils.bindToService(this, this);

    //start ? ?? ?looperhandler
    HandlerThread alnumArtThread = new HandlerThread("Album Art HandlerThread ");
    alnumArtThread.start();
    albumArtHandler = new AlbumArtHandler(alnumArtThread.getLooper());
}