List of usage examples for android.os HandlerThread HandlerThread
public HandlerThread(String name)
From source file:com.google.android.apps.muzei.MuzeiWallpaperService.java
private void initialize() { FirebaseAnalytics.getInstance(this).setUserProperty("device_type", BuildConfig.DEVICE_TYPE); SourceManager.subscribeToSelectedSource(MuzeiWallpaperService.this); mNetworkChangeReceiver = new NetworkChangeReceiver(); IntentFilter networkChangeFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mNetworkChangeReceiver, networkChangeFilter); // Ensure we retry loading the artwork if the network changed while the wallpaper was disabled ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); Intent retryIntent = TaskQueueService.maybeRetryDownloadDueToGainedConnectivity(this); if (retryIntent != null && connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnected()) { startService(retryIntent);/*from w w w . j a v a2 s. com*/ } // Set up a thread to update notifications whenever the artwork changes mNotificationHandlerThread = new HandlerThread("MuzeiWallpaperService-Notification"); mNotificationHandlerThread.start(); mNotificationContentObserver = new ContentObserver(new Handler(mNotificationHandlerThread.getLooper())) { @Override public void onChange(final boolean selfChange, final Uri uri) { NewWallpaperNotificationReceiver.maybeShowNewArtworkNotification(MuzeiWallpaperService.this); } }; getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mNotificationContentObserver); // Set up a thread to update Android Wear whenever the artwork changes mWearableHandlerThread = new HandlerThread("MuzeiWallpaperService-Wearable"); mWearableHandlerThread.start(); mWearableContentObserver = new ContentObserver(new Handler(mWearableHandlerThread.getLooper())) { @Override public void onChange(final boolean selfChange, final Uri uri) { WearableController.updateArtwork(MuzeiWallpaperService.this); } }; getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mWearableContentObserver); // Set up a thread to update the Artwork Info shortcut whenever the artwork changes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { mArtworkInfoShortcutHandlerThread = new HandlerThread("MuzeiWallpaperService-ArtworkInfoShortcut"); mArtworkInfoShortcutHandlerThread.start(); mArtworkInfoShortcutContentObserver = new ContentObserver( new Handler(mArtworkInfoShortcutHandlerThread.getLooper())) { @RequiresApi(api = Build.VERSION_CODES.N_MR1) @Override public void onChange(final boolean selfChange, final Uri uri) { ArtworkInfoShortcutController.updateShortcut(MuzeiWallpaperService.this); } }; getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mArtworkInfoShortcutContentObserver); } mInitialized = true; }
From source file:androidx.media.MediaSession2ImplBase.java
MediaSession2ImplBase(Context context, MediaSessionCompat sessionCompat, String id, MediaPlayerBase player, MediaPlaylistAgent playlistAgent, VolumeProviderCompat volumeProvider, PendingIntent sessionActivity, Executor callbackExecutor, SessionCallback callback) { mContext = context;// w ww.j av a 2s . co m mHandlerThread = new HandlerThread("MediaController2_Thread"); mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); mSessionCompat = sessionCompat; mSession2Stub = new MediaSession2StubImplBase(this); mSessionCompat.setCallback(mSession2Stub, mHandler); mSessionCompat.setSessionActivity(sessionActivity); mId = id; mCallback = callback; mCallbackExecutor = callbackExecutor; mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // TODO: Set callback values properly mPlayerEventCallback = new MyPlayerEventCallback(this); mPlaylistEventCallback = new MyPlaylistEventCallback(this); // Infer type from the id and package name. String libraryService = getServiceName(context, MediaLibraryService2.SERVICE_INTERFACE, id); String sessionService = getServiceName(context, MediaSessionService2.SERVICE_INTERFACE, id); if (sessionService != null && libraryService != null) { throw new IllegalArgumentException( "Ambiguous session type. Multiple" + " session services define the same id=" + id); } else if (libraryService != null) { mSessionToken = new SessionToken2(Process.myUid(), TYPE_LIBRARY_SERVICE, context.getPackageName(), libraryService, id, mSessionCompat.getSessionToken()); } else if (sessionService != null) { mSessionToken = new SessionToken2(Process.myUid(), TYPE_SESSION_SERVICE, context.getPackageName(), sessionService, id, mSessionCompat.getSessionToken()); } else { mSessionToken = new SessionToken2(Process.myUid(), TYPE_SESSION, context.getPackageName(), null, id, mSessionCompat.getSessionToken()); } updatePlayer(player, playlistAgent, volumeProvider); }
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 w w w. 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: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();//ww w .java 2 s. c o m playHandler = new PlayHandler(playThread.getLooper()); }
From source file:de.stadtrallye.rallyesoft.services.UploadService.java
@Override public void onCreate() { super.onCreate(); notes = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); connection = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); connection.getActiveNetworkInfo();/* w w w .j a v a2 s. com*/ Storage.aquireStorage(getApplicationContext(), this); dbProvider = Storage.getDatabaseProvider(); pictureManager = Storage.getPictureManager(); pref = Storage.getAppPreferences(); pref.registerOnSharedPreferenceChangeListener(this); readPrefs(); HandlerThread thread = new HandlerThread("UploadService [UploadThread]"); thread.start(); looper = thread.getLooper(); handler = new UploaderHandler(looper); }
From source file:mobi.cangol.mobile.base.BaseFragment.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.v(TAG, "onCreate"); handlerThread = new HandlerThread(TAG); handlerThread.start();/* w w w. java 2s . c o m*/ handler = new InternalHandler(this, handlerThread.getLooper()); app = (CoreApplication) this.getActivity().getApplication(); if (savedInstanceState == null) { } else { if (null != stack) stack.restoreState(savedInstanceState); } }
From source file:com.android.audiorecorder.ui.ImageViewActvity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_ACTION_BAR); requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); mFileDeleteHandlerThread = new HandlerThread("ImageView"); mFileDeleteHandlerThread.start();//ww w. j av a 2s. c o m mFileDeleteHandler = new Handler(mFileDeleteHandlerThread.getLooper(), mFileProcHandlerCallback); orientationEventListener = new MyOrientationEventListener(this); orientationEventListener.enable(); setContentView(R.layout.layout_image_view); rootView = (RotateLayout) findViewById(R.id.picture_view_root); /*rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);*/ //ImageCacheParams cacheParams = new ImageCacheParams(this, IMAGE_CACHE_DIR); final DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final int height = displayMetrics.heightPixels; final int width = displayMetrics.widthPixels; final int longest = (height > width ? height : width) * 2 / 3; mBitmapUtils = new BitmapUtils(this); mBitmapUtils.configDefaultBitmapConfig(Config.RGB_565); mBitmapUtils.configDefaultAutoRotation(true); mBitmapUtils.configDiskCacheEnabled(true); mBitmapUtils.configMemoryCacheEnabled(true); Intent intent = getIntent(); mGalleryViewPager = (GalleryViewPager) findViewById(R.id.viewer); pagerAdapter = new FilePagerAdapter(this, 100, 0, mBitmapUtils, null); mGalleryViewPager.setAdapter(pagerAdapter); mGalleryViewPager.setOffscreenPageLimit(1); final BitmapDisplayConfig bd = new BitmapDisplayConfig(); bd.setAutoRotation(true); bd.setBitmapConfig(Config.RGB_565); mGalleryViewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int index) { mBitmapUtils.display(mGalleryViewPager.mCurrentView, pagerAdapter.getCurrentPath(0, 0)); /*ImageCache imageCache = mImageFetcher.getImageCache(); if(imageCache != null) { BitmapDrawable value = imageCache.getBitmapFromMemCache(pagerAdapter.getCurrentPath(0, mCurrentSelect)); if(value != null){ mGalleryViewPager.mCurrentView.setImageBitmap(value.getBitmap()); } } Log.i(TAG, "---> page index " + index + " select.");*/ } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int state) { if (ViewPager.SCROLL_STATE_IDLE == state) { mHandler.removeMessages(MSG_LOAD_BITMAP); mHandler.sendEmptyMessageDelayed(MSG_LOAD_BITMAP, 0); } } }); mHandler.removeMessages(MSG_LOAD_BITMAP); mHandler.sendEmptyMessageDelayed(MSG_LOAD_BITMAP, 50); }
From source file:com.nhn.android.archetype.base.AABaseApplicationOrg.java
protected void init() { workExecutor = Executors.newCachedThreadPool(); statsWorkExecutor = Executors.newFixedThreadPool(1); handler = new Handler(Looper.getMainLooper()); backgroundHandlerThread = new HandlerThread("BandBackgroundHandlerThread"); backgroundHandlerThread.start();// w w w. j av a 2 s .c o m backgroundHandler = new Handler(backgroundHandlerThread.getLooper()); JsonWorker.init(); logger.d("Application init completed....."); }
From source file:com.marianhello.bgloc.LocationService.java
@Override public void onCreate() { super.onCreate(); log = LoggerManager.getLogger(LocationService.class); log.info("Creating LocationService"); // An Android handler thread internally operates on a looper. handlerThread = new HandlerThread("LocationService.HandlerThread"); handlerThread.start();/*from w ww. ja v a 2 s. c o m*/ // An Android service handler is a handler running on a specific background thread. serviceHandler = new ServiceHandler(handlerThread.getLooper()); dao = (DAOFactory.createLocationDAO(this)); syncAccount = AccountHelper.CreateSyncAccount(this, AuthenticatorService.getAccount(getStringResource(Config.ACCOUNT_TYPE_RESOURCE))); registerReceiver(connectivityChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:com.example.activitydemo.app.service.GameService.java
public void startForeground() { Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.game_in_progress)) .setContentIntent(buildActivityPendingIntent()).setSmallIcon(getApplicationInfo().icon) .setOngoing(true).build();/* ww w .ja v a2 s. c o m*/ mHandlerThread = new HandlerThread("GameHandler"); mHandlerThread.start(); mGameHandler = new GameHandler(mHandlerThread.getLooper(), mGameCallbacks); super.startForeground(R.string.app_name, notification); }