List of usage examples for android.os HandlerThread HandlerThread
public HandlerThread(String name)
From source file:com.readystatesoftware.android.geras.mqtt.GerasMqttService.java
@Override public void onCreate() { super.onCreate(); mDeviceId = String.format("an_%s", Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); mConnectionThread = new HandlerThread("mqtt-connection"); mConnectionThread.start();/*from w w w. j a v a 2 s . com*/ mConnectionHandler = new Handler(mConnectionThread.getLooper()); mDataStore = new MqttDefaultFilePersistence(getCacheDir().getAbsolutePath()); IntentFilter f = new IntentFilter(); f.addAction(ACTION_PUBLISH_DATAPOINT); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, f); }
From source file:com.wbtech.ums.UmsAgent.java
private UmsAgent() { HandlerThread localHandlerThread = new HandlerThread("UmsAgent"); localHandlerThread.start();//from ww w .j a v a 2s. c o m this.handler = new Handler(localHandlerThread.getLooper()); }
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();//from w w w .j a v a 2s. co m mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper); }
From source file:com.cyanogenmod.effem.FmRadio.java
/** * Required method from parent class//w w w. j a v a 2s.com * * @param icicle - The previous instance of this app */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); context = getApplicationContext(); setContentView(R.layout.main); // restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); mSelectedBand = settings.getInt("selectedBand", 1); mCurrentFrequency = settings.getInt("currentFrequency", 0); if (context.getResources().getBoolean(R.bool.speaker_supported)) { mSelectedOutput = settings.getInt("selectedOutput", 0) > 0 ? 1 : 0; } // misc setup setVolumeControlStream(AudioManager.STREAM_MUSIC); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // worker thread for async execution of FM stuff mWorker = new HandlerThread("EffemWorker"); mWorker.start(); mWorkerHandler = new Handler(mWorker.getLooper()); // ui preparations setupButtons(); }
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();//from www . ja v a 2s . com } 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:ch.ethz.coss.nervousnet.vm.sensors.NoiseSensor.java
@Override public boolean start() { if (sensorState == NervousnetVMConstants.SENSOR_STATE_NOT_AVAILABLE) { NNLog.d(LOG_TAG, "Cancelled NoiseSensor sensor as Sensor is not available."); return false; } else if (sensorState == NervousnetVMConstants.SENSOR_STATE_AVAILABLE_PERMISSION_DENIED) { NNLog.d(LOG_TAG, "Cancelled NoiseSensor sensor as permission denied by user."); return false; } else if (sensorState == NervousnetVMConstants.SENSOR_STATE_AVAILABLE_BUT_OFF) { NNLog.d(LOG_TAG, "Cancelled NoiseSensor sensor as Sensor state is switched off."); return false; }//from ww w.j a v a 2 s.c o m if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(mContext, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { setSensorState(NervousnetVMConstants.SENSOR_STATE_AVAILABLE_PERMISSION_DENIED); return false; } NNLog.d(LOG_TAG, "Starting NoiseSensor sensor with state = " + sensorState); hthread = new HandlerThread("HandlerThread"); hthread.start(); handler = new Handler(hthread.getLooper()); final Runnable run = new Runnable() { @Override public void run() { startRecording(500); if (handler != null) handler.postDelayed(this, 1000);// NervousnetVMConstants.sensor_freq_constants[3][sensorState // - 1]); // TODO: test this } }; boolean flag = handler.postDelayed(run, 500); return true; }
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 ww w.j a v a 2s.c o 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:grupo19.locmess19.Services.LocationUpdatesService.java
@SuppressLint("WifiManagerLeak") @Override// w w w . ja v a2 s. com 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:com.amazonaws.mobileconnectors.s3.transferutility.TransferService.java
/** * <ul>//from ww w . j a v a 2 s .c o m * <li>The service starts upon intents from transfer utility.</li> * <li>It remains alive when there are active transfers.</li> * <li>It also stays alive when network is disconnected and there are * transfers waiting.</li> * </ul> */ @Override public void onCreate() { super.onCreate(); LOGGER.debug("Starting Transfer Service"); dbUtil = new TransferDBUtil(getApplicationContext()); updater = new TransferStatusUpdater(dbUtil); handlerThread = new HandlerThread(TAG + "-AWSTransferUpdateHandlerThread"); handlerThread.start(); setHandlerLooper(handlerThread.getLooper()); }
From source file:com.google.android.gms.location.sample.locationupdatesforegroundservice.LocationUpdatesService.java
@Override public void onCreate() { mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); mGoogleApiClient.connect();//from w ww . j a va2s.c om createLocationRequest(); HandlerThread handlerThread = new HandlerThread(TAG); handlerThread.start(); mServiceHandler = new Handler(handlerThread.getLooper()); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); }