Java Code Examples for android.os.Process#THREAD_PRIORITY_BACKGROUND

The following examples show how to use android.os.Process#THREAD_PRIORITY_BACKGROUND . 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: ArchiveGalleryProvider.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  super.start();

  int id = sIdGenerator.incrementAndGet();

  archiveThread = new PriorityThread(
      new ArchiveTask(), "ArchiveTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
  archiveThread.start();

  decodeThread = new PriorityThread(
      new DecodeTask(), "DecodeTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
  decodeThread.start();
}
 
Example 2
Source File: DispatchService.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "onCreate()");
    HandlerThread thread = new HandlerThread("dispatcher",
            Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    // Get the HandlerThread's Looper and use it for our Handler
    mServiceLooper = thread.getLooper();
    mHandler = new Handler(mServiceLooper, getHandlerCallback());
    if (!initialized)
        initialized = checkInit();
    mNotificationFactory = NotificationFactory.getInstance(this);
    mNotificationFactory.setContentTitle(R.string.network_alert);
}
 
Example 3
Source File: ScreenshotService.java    From save-for-offline with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
	HandlerThread thread = new HandlerThread("WebpageScreenshotService", Process.THREAD_PRIORITY_BACKGROUND);
	thread.start();

	mServiceHandler = new ServiceHandler(thread.getLooper());
}
 
Example 4
Source File: WorkHandler.java    From ImageFrame with Apache License 2.0 5 votes vote down vote up
public WorkHandler() {
  super("WorkHandler", Process.THREAD_PRIORITY_BACKGROUND);
  start();
  workHandler = new Handler(getLooper()) {
    @Override
    public void handleMessage(Message msg) {
      if (messageProxyList != null) {
        for (WorkMessageProxy workMessageProxy : messageProxyList) {
          workMessageProxy.handleMessage(msg);
        }
      }
    }
  };
}
 
Example 5
Source File: ArchiveGalleryProvider.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  super.start();

  int id = sIdGenerator.incrementAndGet();

  archiveThread = new PriorityThread(
      new ArchiveTask(), "ArchiveTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
  archiveThread.start();

  decodeThread = new PriorityThread(
      new DecodeTask(), "DecodeTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
  decodeThread.start();
}
 
Example 6
Source File: DownloaderService.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@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();
    if (BuildConfig.DEBUG) {
        serviceLooper.setMessageLogging(new LogPrinter(Log.DEBUG, ServiceHandler.TAG));
    }
    serviceHandler = new ServiceHandler(serviceLooper);
    localBroadcastManager = LocalBroadcastManager.getInstance(this);
}
 
Example 7
Source File: NetworkServerService.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread(
            "ServiceStartArguments",
            Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();

    serviceLooper = thread.getLooper();
    serviceHandler = createServiceHandler(serviceLooper, this);
}
 
Example 8
Source File: NetworkWatchlistService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public NetworkWatchlistService(Context context) {
    mContext = context;
    mConfig = WatchlistConfig.getInstance();
    mHandlerThread = new ServiceThread(TAG, Process.THREAD_PRIORITY_BACKGROUND,
                    /* allowIo */ false);
    mHandlerThread.start();
    mNetworkWatchlistHandler = new WatchlistLoggingHandler(mContext,
            mHandlerThread.getLooper());
    mNetworkWatchlistHandler.reportWatchlistIfNecessary();
}
 
Example 9
Source File: MockDefaultExecutorSupplier.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
private MockDefaultExecutorSupplier() {
//        this.sdkExternalExecutorTest = sdkExternalExecutorTest;

        // setting the thread factory
        ThreadFactory backgroundPriorityThreadFactory = new
                MockPriorityThreadFactory(Process.THREAD_PRIORITY_BACKGROUND);

        // setting the thread pool executor for mForBackgroundTasks;
        mForBackgroundTasks = new ThreadPoolExecutor(
                NUMBER_OF_CORES * 2,
                NUMBER_OF_CORES * 2,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(),
                backgroundPriorityThreadFactory
        );

        // setting the thread pool executor for mForLightWeightBackgroundTasks;
        mForLightWeightBackgroundTasks = new ThreadPoolExecutor(
                NUMBER_OF_CORES * 2,
                NUMBER_OF_CORES * 2,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(),
                backgroundPriorityThreadFactory
        );

        // setting the thread pool executor for mMainThreadExecutor;
        mMainThreadExecutor = new MockMainThreadExecutor();
    }
 
Example 10
Source File: MusicService.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    wakeLock.setReferenceCounted(false);

    musicPlayerHandlerThread = new HandlerThread("PlaybackHandler");
    musicPlayerHandlerThread.start();
    playerHandler = new PlaybackHandler(this, musicPlayerHandlerThread.getLooper());

    playback = new MultiPlayer(this);
    playback.setCallbacks(this);

    setupMediaSession();

    // queue saving needs to run on a separate thread so that it doesn't block the playback handler events
    queueSaveHandlerThread = new HandlerThread("QueueSaveHandler", Process.THREAD_PRIORITY_BACKGROUND);
    queueSaveHandlerThread.start();
    queueSaveHandler = new QueueSaveHandler(this, queueSaveHandlerThread.getLooper());

    uiThreadHandler = new Handler();

    registerReceiver(widgetIntentReceiver, new IntentFilter(APP_WIDGET_UPDATE));
    registerReceiver(updateFavoriteReceiver, new IntentFilter(FAVORITE_STATE_CHANGED));

    initNotification();

    mediaStoreObserver = new MediaStoreObserver(this, playerHandler);
    throttledSeekHandler = new ThrottledSeekHandler(this, playerHandler);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);

    PreferenceUtil.getInstance().registerOnSharedPreferenceChangedListener(this);

    restoreState();

    mPackageValidator = new PackageValidator(this, R.xml.allowed_media_browser_callers);
    mMusicProvider = new AutoMusicProvider(this);

    sendBroadcast(new Intent("com.poupa.vinylmusicplayer.VINYL_MUSIC_PLAYER_MUSIC_SERVICE_CREATED"));
}
 
Example 11
Source File: TaskService.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
protected int getThreadPriority() {
    return Process.THREAD_PRIORITY_BACKGROUND;
}
 
Example 12
Source File: EventConditionProvider.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public EventConditionProvider() {
    if (DEBUG) Slog.d(TAG, "new " + SIMPLE_NAME + "()");
    mThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
    mThread.start();
    mWorker = new Handler(mThread.getLooper());
}
 
Example 13
Source File: StatusService.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
private Handler startHandlerThread(String name) {
    HandlerThread thread = new HandlerThread(name, Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    return new Handler(thread.getLooper(), this);
}
 
Example 14
Source File: LogDataTransfer.java    From OkHttpProfiler with Apache License 2.0 4 votes vote down vote up
public LogDataTransfer() {
    final HandlerThread handlerThread = new HandlerThread("OkHttpProfiler", Process.THREAD_PRIORITY_BACKGROUND);
    handlerThread.start();
    mHandler = new LogBodyHandler(handlerThread.getLooper());
}
 
Example 15
Source File: MusicService.java    From Orin with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    wakeLock.setReferenceCounted(false);

    musicPlayerHandlerThread = new HandlerThread("PlaybackHandler");
    musicPlayerHandlerThread.start();
    playerHandler = new PlaybackHandler(this, musicPlayerHandlerThread.getLooper());

    playback = new MultiPlayer(this);
    playback.setCallbacks(this);

    setupMediaSession();

    // queue saving needs to run on a separate thread so that it doesn't block the playback handler events
    queueSaveHandlerThread = new HandlerThread("QueueSaveHandler", Process.THREAD_PRIORITY_BACKGROUND);
    queueSaveHandlerThread.start();
    queueSaveHandler = new QueueSaveHandler(this, queueSaveHandlerThread.getLooper());

    uiThreadHandler = new Handler();

    registerReceiver(widgetIntentReceiver, new IntentFilter(APP_WIDGET_UPDATE));

    initNotification();

    mediaStoreObserver = new MediaStoreObserver(playerHandler);
    throttledSeekHandler = new ThrottledSeekHandler(playerHandler);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);

    PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);

    restoreState();

    mediaSession.setActive(true);

    sendBroadcast(new Intent("com.kabouzeid.gramophone.PHONOGRAPH_MUSIC_SERVICE_CREATED"));
}
 
Example 16
Source File: MusicService.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    wakeLock.setReferenceCounted(false);

    musicPlayerHandlerThread = new HandlerThread("PlaybackHandler");
    musicPlayerHandlerThread.start();
    playerHandler = new PlaybackHandler(this, musicPlayerHandlerThread.getLooper());

    playback = new MultiPlayer(this);
    playback.setCallbacks(this);

    setupMediaSession();

    // queue saving needs to run on a separate thread so that it doesn't block the playback handler events
    queueSaveHandlerThread = new HandlerThread("QueueSaveHandler", Process.THREAD_PRIORITY_BACKGROUND);
    queueSaveHandlerThread.start();
    queueSaveHandler = new QueueSaveHandler(this, queueSaveHandlerThread.getLooper());

    uiThreadHandler = new Handler();

    registerReceiver(widgetIntentReceiver, new IntentFilter(APP_WIDGET_UPDATE));

    initNotification();

    mediaStoreObserver = new MediaStoreObserver(playerHandler);
    throttledSeekHandler = new ThrottledSeekHandler(playerHandler);

    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);

    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Albums.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Artists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Genres.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);


    PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);

    restoreState();

    mediaSession.setActive(true);

    sendBroadcast(new Intent("com.kabouzeid.gramophone.PHONOGRAPH_MUSIC_SERVICE_CREATED"));
}
 
Example 17
Source File: WorkThreadExecutor.java    From Flora with MIT License 4 votes vote down vote up
public WorkThreadExecutor() {
    mHandlerThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper());
}
 
Example 18
Source File: LaunchTask.java    From Rocket with Apache License 2.0 4 votes vote down vote up
@Override
public int priority() {
    return Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE;
}
 
Example 19
Source File: MediaPlayer.java    From droidel with Apache License 2.0 4 votes vote down vote up
/** @hide */
public void addSubtitleSource(InputStream is, MediaFormat format)
        throws IllegalStateException
{
    final InputStream fIs = is;
    final MediaFormat fFormat = format;

    // Ensure all input streams are closed.  It is also a handy
    // way to implement timeouts in the future.
    synchronized(mOpenSubtitleSources) {
        mOpenSubtitleSources.add(is);
    }

    // process each subtitle in its own thread
    final HandlerThread thread = new HandlerThread("SubtitleReadThread",
          Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE);
    thread.start();
    Handler handler = new Handler(thread.getLooper());
    handler.post(new Runnable() {
        private int addTrack() {
            if (fIs == null || mSubtitleController == null) {
                return MEDIA_INFO_UNSUPPORTED_SUBTITLE;
            }

            SubtitleTrack track = mSubtitleController.addTrack(fFormat);
            if (track == null) {
                return MEDIA_INFO_UNSUPPORTED_SUBTITLE;
            }

            // TODO: do the conversion in the subtitle track
            Scanner scanner = new Scanner(fIs, "UTF-8");
            String contents = scanner.useDelimiter("\\A").next();
            synchronized(mOpenSubtitleSources) {
                mOpenSubtitleSources.remove(fIs);
            }
            scanner.close();
            mOutOfBandSubtitleTracks.add(track);
            track.onData(contents, true /* eos */, ~0 /* runID: keep forever */);
            return MEDIA_INFO_EXTERNAL_METADATA_UPDATE;
        }

        public void run() {
            int res = addTrack();
            if (mEventHandler != null) {
                Message m = mEventHandler.obtainMessage(MEDIA_INFO, res, 0, null);
                mEventHandler.sendMessage(m);
            }
            thread.getLooper().quitSafely();
        }
    });
}
 
Example 20
Source File: BaseCameraManager.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void startBackgroundThread() {
    mBackgroundThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}