List of usage examples for android.os HandlerThread HandlerThread
public HandlerThread(String name, int priority)
From source file:com.uphyca.idobata.android.service.IdobataService.java
private void ensureHandler() { HandlerThread t = new HandlerThread("IdobataService", Process.THREAD_PRIORITY_BACKGROUND); t.start();//ww w. jav a 2s . co m mServiceLooper = t.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper); }
From source file:com.speedtong.example.ui.chatting.ChattingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { LogUtil.d(TAG, "onCreate"); super.onCreate(savedInstanceState); brand = Build.MODEL + Build.BRAND;//from w w w .j a v a 2 s .com TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); uuid = tm.getDeviceId(); messageDao = MessageDao.getInstance(this); toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); sdpath = Environment.getExternalStorageDirectory().getAbsolutePath(); // ??? initView(); // ??? initActivityState(savedInstanceState); final ArrayList<ECMessage> list = IMessageSqlManager.queryIMessageList(mThread, 20, getMessageAdapterLastMessageTime() + ""); mListView.post(new Runnable() { @Override public void run() { mChattingAdapter.setData(list); if (mChattingAdapter.getCount() < 20) { //mPullDownView.setPullEnabled(false); //mPullDownView.setPullViewVisibed(false); } mListView.clearFocus(); mChattingAdapter.notifyDataSetChanged(); mListView.setSelection(mChattingAdapter.getCount()); } }); // ?IM?API mChatManager = SDKCoreHelper.getECChatManager(); HandlerThread thread = new HandlerThread("ChattingVoiceRecord", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); // Get the HandlerThread's Looper and use it for our Handler mChattingLooper = thread.getLooper(); mVoiceHandler = new Handler(mChattingLooper); mVoiceHandler.post(new Runnable() { @Override public void run() { doEmojiPanel(); } }); }
From source file:paulscode.android.mupen64plusae.task.CacheRomInfoService.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();/*w w w. java 2 s. c o m*/ // 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.scanning_title)) .setContentText(getString(R.string.toast_pleaseWait)).setContentIntent(pendingIntent); startForeground(ONGOING_NOTIFICATION_ID, builder.build()); }
From source file:com.mozilla.autophone.usbwatchdog.USBService.java
@Override public void onCreate() { HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND); thread.start();//w ww . j a v a2s . co m int permission = ContextCompat.checkSelfPermission(this, Manifest.permission.REBOOT); mPermissions = (permission == PackageManager.PERMISSION_GRANTED); permission = ContextCompat.checkSelfPermission(this, Manifest.permission.DUMP); mPermissions = mPermissions && (permission == PackageManager.PERMISSION_GRANTED); if (mPermissions) { Log.i("USBWatchdog", "Permissions granted. Using PowerManager."); } else { Log.i("USBWatchdog", "Permissions not granted. Using su."); } mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, mPermissions); }
From source file:com.socialdisasters.service.ChatService.java
@Override public void onCreate() { // call onCreate of the super-class super.onCreate(); // create a new background looper mUpdateThread = new HandlerThread(TAG, android.os.Process.THREAD_PRIORITY_BACKGROUND); mUpdateThread.start();//from ww w .j av a2s. c o m Looper looper = mUpdateThread.getLooper(); mUpdateHandler = new UpdateHandler(looper); // create registration Registration registration = new Registration("chat"); registration.add(PRESENCE_GROUP_EID); try { initialize(registration); } catch (ServiceNotAvailableException e) { } catch (SecurityException ex) { } // register to presence changes SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(mPrefListener); }
From source file:org.anhonesteffort.flock.CalendarCopyService.java
@Override public void onCreate() { HandlerThread thread = new HandlerThread("CalendarCopyService", HandlerThread.NORM_PRIORITY); thread.start();//from w ww . ja v a 2 s. c om serviceLooper = thread.getLooper(); serviceHandler = new ServiceHandler(serviceLooper); notifyManager = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder = new NotificationCompat.Builder(getBaseContext()); accountErrors = new LinkedList<Bundle>(); }
From source file:paulscode.android.mupen64plusae.jni.CoreService.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_DEFAULT); thread.start();//from www. j a v a2 s. co m // Get the HandlerThread's Looper and use it for our Handler Looper serviceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(serviceLooper); }
From source file:com.eTilbudsavis.etasdk.SyncManager.java
/** * Default constructor for the {@link SyncManager} * @param eta An Eta instance// w ww. j a v a 2 s . co m */ public SyncManager(Eta eta) { mEta = eta; SyncLog.setLog(LOG); SyncLog.setLogSync(LOG_SYNC); // Create a new thread for a handler, so that i can later post content to that thread. mThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND); mThread.start(); mHandler = new Handler(mThread.getLooper()); mDelivery = new HandlerDelivery(mHandler); }
From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java
@Override public void onCreate() { mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); thread = new HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND); thread.start();/* w w w .j a v a 2 s . c om*/ mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper); }
From source file:com.dellingertech.andevcon.mocklocationprovider.SendMockLocationService.java
@Override public void onCreate() { /*//ww w. j ava2 s . co m * Load the mock location data from MockLocationConstants.java */ // mLocationArray = buildTestLocationArray(LocationUtils.WAYPOINTS_LAT, // LocationUtils.WAYPOINTS_LNG, LocationUtils.WAYPOINTS_ACCURACY); mLocationArray = buildTestLocationArray("testdata1.csv", 1.0f); /* * Prepare to send status updates back to the main activity. * Get a local broadcast manager instance; broadcast intents sent via this * manager are only available within the this app. */ mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); /* * Create a new background thread with an associated Looper that processes Message objects * from a MessageQueue. The Looper allows test Activities to send repeated requests to * inject mock locations from this Service. */ mWorkThread = new HandlerThread("UpdateThread", Process.THREAD_PRIORITY_BACKGROUND); /* * Start the thread. Nothing actually runs until the Looper for this thread dispatches a * Message to the Handler. */ mWorkThread.start(); // Get the Looper for the thread mUpdateLooper = mWorkThread.getLooper(); /* * Create a Handler object and pass in the Looper for the thread. * The Looper can now dispatch Message objects to the Handler's handleMessage() method. */ mUpdateHandler = new UpdateHandler(mUpdateLooper); // Indicate that testing has not yet started mTestStarted = false; }