List of usage examples for android.os HandlerThread start
public synchronized void start()
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(); mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, this); mLocalBroadcastMgr = LocalBroadcastManager.getInstance(getApplicationContext()); // Initialize the session map mCommSessions = new ConcurrentHashMap<String, ASCIICommunicationSession>(); }
From source file:com.example.joeroger.homework2.activity.WeatherActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Turn on strict mode in debug builds if (BuildConfig.DEBUG) { StrictMode.enableDefaults();/* w ww . j av a 2 s . c o m*/ } setContentView(R.layout.activity_weather); setSupportActionBar((Toolbar) findViewById(R.id.toolBar)); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(false); Spinner spinner = (Spinner) findViewById(R.id.city_spinner); citySpinnerCursorAdapter = new CitySpinnerCursorAdapter(actionBar.getThemedContext(), null); spinner.setAdapter(citySpinnerCursorAdapter); spinner.setOnItemSelectedListener(this); ViewCompat.setElevation(spinner, 0); } HandlerThread handlerThread = new HandlerThread("WeatherActivityThread"); handlerThread.start(); handler = new Handler(handlerThread.getLooper(), this); resolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR); CityConditionsLoaderCallbacks.initLoader(getSupportLoaderManager(), this, this, CitySpinnerCursorAdapter.PROJECTION, CityConditionsContract.WHERE_CURRENT_OR_FAVORITE, CityConditionsContract.WHERE_CURRENT_OR_FAVORITE_ARGS); }
From source file:edu.mit.media.funf.pipeline.BasicPipeline.java
@Override public void onCreate(FunfManager manager) { if (archive == null) { archive = new DefaultArchive(manager, name); }//from w w w. ja v a 2 s. c o m if (uploader == null) { uploader = new UploadService(manager); uploader.start(); } this.manager = manager; reloadDbHelper(manager); HandlerThread thread = new HandlerThread(getClass().getName()); thread.start(); this.looper = thread.getLooper(); this.handler = new Handler(looper, callback); enabled = true; for (JsonElement dataRequest : data) { manager.requestData(this, dataRequest); } for (Map.Entry<String, Schedule> schedule : schedules.entrySet()) { manager.registerPipelineAction(this, schedule.getKey(), schedule.getValue()); } }
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(); // 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);/*from w w w . j ava 2 s. c o m*/ // 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:com.unlp.tesis.steer.LocationService.java
@Override public void onCreate() { //GEOFENCES//from w w w . j a v a2 s. c o m // 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:zuo.biao.library.base.BaseFragmentActivity.java
/**? * @param threadName//from w w w. ja va 2 s. c om * @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: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(); 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//from w w w .j a v a 2 s .c om 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: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(); playHandler = new PlayHandler(playThread.getLooper()); }
From source file:org.fdroid.fdroid.net.DownloaderService.java
@Override public void onCreate() { super.onCreate(); Utils.debugLog(TAG, "Creating downloader service."); HandlerThread thread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND); thread.start(); serviceLooper = thread.getLooper();// w w w. j a v a 2 s . com serviceHandler = new ServiceHandler(serviceLooper); localBroadcastManager = LocalBroadcastManager.getInstance(this); }
From source file:com.bitants.wally.fragments.LatestFragment.java
private void setupHandlers() { HandlerThread handlerThread = new HandlerThread("Toplist.background"); handlerThread.start(); backgroundHandler = new Handler(handlerThread.getLooper(), this); uiHandler = new Handler(getActivity().getMainLooper(), this); }