Java Code Examples for android.os.HandlerThread#setPriority()
The following examples show how to use
android.os.HandlerThread#setPriority() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidImmediateDispatcher.java From actor-platform with GNU Affero General Public License v3.0 | 7 votes |
public AndroidImmediateDispatcher(String name, ThreadPriority priority) { handlerThread = new HandlerThread(name); switch (priority) { case HIGH: handlerThread.setPriority(Thread.MAX_PRIORITY); case LOW: handlerThread.setPriority(Thread.MIN_PRIORITY); default: case NORMAL: handlerThread.setPriority(Thread.NORM_PRIORITY); } handlerThread.start(); // Wait for Looper ready while (handlerThread.getLooper() == null) { } handler = new Handler(handlerThread.getLooper()); }
Example 2
Source File: ViewCrawler.java From ans-android-sdk with GNU General Public License v3.0 | 6 votes |
public ViewCrawler(Context context) { mContext = context; mEditState = new EditState(); mDeviceInfo = VisUtils.getDeviceInfo(context); DisplayMetrics dm = Resources.getSystem().getDisplayMetrics(); mScaledDensity = dm.scaledDensity; width = dm.widthPixels; height = dm.heightPixels; final HandlerThread thread = new HandlerThread(ViewCrawler.class.getCanonicalName()); thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mMessageThreadHandler = new ViewCrawlerHandler(context, thread.getLooper()); mDynamicEventTracker = new DynamicEventTracker(); mSensorHelper = new SensorHelper(); mMainThreadHandler = new Handler(Looper.getMainLooper()); }
Example 3
Source File: HandlerFactory.java From Camera2 with Apache License 2.0 | 6 votes |
/** * @param lifetime The lifetime of the associated handler's thread. * @param threadName The name to assign to the created thread. * @param javaThreadPriority The Java thread priority to use for this thread. * @return A handler backed by a new thread. */ public Handler create(Lifetime lifetime, String threadName, int javaThreadPriority) { final HandlerThread thread = new HandlerThread(threadName); thread.start(); thread.setPriority(javaThreadPriority); lifetime.add(new SafeCloseable() { @Override public void close() { thread.quitSafely(); } }); return new Handler(thread.getLooper()); }
Example 4
Source File: CTABTestController.java From clevertap-android-sdk with MIT License | 6 votes |
public CTABTestController(Context context, CleverTapInstanceConfig config, String guid, CTABTestListener listener) { this.varCache = new CTVarCache(); this.enableEditor = config.isUIEditorEnabled(); this.config = config; this.guid = guid; this.setListener(listener); this.uiEditor = new UIEditor(context, config); final HandlerThread thread = new HandlerThread(CTABTestController.class.getCanonicalName()); thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND); thread.start(); executionThreadHandler = new ExecutionThreadHandler(context, config, thread.getLooper()); executionThreadHandler.start(); if (enableEditor) { final Application app = (Application) context.getApplicationContext(); app.registerActivityLifecycleCallbacks(new LifecycleCallbacks()); } else { config.getLogger().debug(config.getAccountId(), "UIEditor connection is disabled"); } applyStoredExperiments(); }
Example 5
Source File: AppModule.java From android-migrate-to-jobs with Apache License 2.0 | 5 votes |
@Provides @Singleton public EventBus provideEventBus() { HandlerThread ht = new HandlerThread("eventbus"); ht.setPriority(Thread.NORM_PRIORITY - 1); ht.start(); return new EventBus(ht.getLooper()); }
Example 6
Source File: DataMoveActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mBackgroundThread = new HandlerThread("DataMoveThread"); mBackgroundThread.setPriority(Thread.MAX_PRIORITY); mBackgroundThread.start(); mBackgroundHandler = new Handler(mBackgroundThread.getLooper()); }
Example 7
Source File: DataImportActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mBackgroundThread = new HandlerThread("DataImportThread"); mBackgroundThread.setPriority(Thread.MIN_PRIORITY); mBackgroundThread.start(); mBackgroundHandler = new Handler(mBackgroundThread.getLooper()); }
Example 8
Source File: Debug.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void initHandler(){ HandlerThread temp = new HandlerThread(Debug.class.getCanonicalName()); //if you send a lot of data through the debug interface, you need this for avoid delay that //can trigger a timeout temp.setPriority(Thread.MAX_PRIORITY); temp.start(); mNotifyThread= new Handler(temp.getLooper()); }
Example 9
Source File: PjSipService.java From react-native-sip with GNU General Public License v3.0 | 4 votes |
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (!mInitialized) { if (intent != null && intent.hasExtra("service")) { mServiceConfiguration = ServiceConfigurationDTO.fromMap((Map) intent.getSerializableExtra("service")); } mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mEmitter = new PjSipBroadcastEmiter(this); mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE); mPowerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock"); mWifiLock.setReferenceCounted(false); mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); mGSMIdle = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; IntentFilter phoneStateFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mPhoneStateChangedReceiver, phoneStateFilter); mInitialized = true; job(new Runnable() { @Override public void run() { load(); } }); } if (intent != null) { job(new Runnable() { @Override public void run() { handle(intent); } }); } return START_NOT_STICKY; }
Example 10
Source File: OneCameraZslImpl.java From Camera2 with Apache License 2.0 | 4 votes |
/** * Instantiates a new camera based on Camera 2 API. * * @param device The underlying Camera 2 device. * @param characteristics The device's characteristics. * @param pictureSize the size of the final image to be taken. */ OneCameraZslImpl(CameraDevice device, CameraCharacteristics characteristics, Size pictureSize) { Log.v(TAG, "Creating new OneCameraZslImpl"); mDevice = device; mCharacteristics = characteristics; mLensRange = LensRangeCalculator .getDiopterToRatioCalculator(characteristics); mDirection = new CameraDirectionProvider(mCharacteristics); mFullSizeAspectRatio = calculateFullSizeAspectRatio(characteristics); mCameraThread = new HandlerThread("OneCamera2"); // If this thread stalls, it will delay viewfinder frames. mCameraThread.setPriority(Thread.MAX_PRIORITY); mCameraThread.start(); mCameraHandler = new Handler(mCameraThread.getLooper()); mCameraListenerThread = new HandlerThread("OneCamera2-Listener"); mCameraListenerThread.start(); mCameraListenerHandler = new Handler(mCameraListenerThread.getLooper()); // TODO: Encoding on multiple cores results in preview jank due to // excessive GC. int numEncodingCores = CameraUtil.getNumCpuCores(); mImageSaverThreadPool = new ThreadPoolExecutor(numEncodingCores, numEncodingCores, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); mCaptureManager = new ImageCaptureManager(MAX_CAPTURE_IMAGES, mCameraListenerHandler, mImageSaverThreadPool); mCaptureManager.setCaptureReadyListener(new ImageCaptureManager.CaptureReadyListener() { @Override public void onReadyStateChange(boolean capturePossible) { mReadyStateManager.setInput(ReadyStateRequirement.CAPTURE_MANAGER_READY, capturePossible); } }); // Listen for changes to auto focus state and dispatch to // mFocusStateListener. mCaptureManager.addMetadataChangeListener(CaptureResult.CONTROL_AF_STATE, new ImageCaptureManager.MetadataChangeListener() { @Override public void onImageMetadataChange(Key<?> key, Object oldValue, Object newValue, CaptureResult result) { FocusStateListener listener = mFocusStateListener; if (listener != null) { listener.onFocusStatusUpdate( AutoFocusHelper.stateFromCamera2State( result.get(CaptureResult.CONTROL_AF_STATE)), result.getFrameNumber()); } } }); // Allocate the image reader to store all images received from the // camera. if (pictureSize == null) { // TODO The default should be selected by the caller, and // pictureSize should never be null. pictureSize = getDefaultPictureSize(); } mCaptureImageReader = ImageReader.newInstance(pictureSize.getWidth(), pictureSize.getHeight(), sCaptureImageFormat, MAX_CAPTURE_IMAGES); mCaptureImageReader.setOnImageAvailableListener(mCaptureManager, mCameraHandler); mMediaActionSound.load(MediaActionSound.SHUTTER_CLICK); }
Example 11
Source File: PjSipService.java From react-native-pjsip with GNU General Public License v3.0 | 4 votes |
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (!mInitialized) { if (intent != null && intent.hasExtra("service")) { mServiceConfiguration = ServiceConfigurationDTO.fromMap((Map) intent.getSerializableExtra("service")); } mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mEmitter = new PjSipBroadcastEmiter(this); mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE); mPowerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock"); mWifiLock.setReferenceCounted(false); mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); mGSMIdle = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; IntentFilter phoneStateFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mPhoneStateChangedReceiver, phoneStateFilter); mInitialized = true; job(new Runnable() { @Override public void run() { load(); } }); } if (intent != null) { job(new Runnable() { @Override public void run() { handle(intent); } }); } return START_NOT_STICKY; }