List of usage examples for android.os Process THREAD_PRIORITY_BACKGROUND
int THREAD_PRIORITY_BACKGROUND
To view the source code for android.os Process THREAD_PRIORITY_BACKGROUND.
Click Source Link
From source file:com.snda.mymarket.providers.downloads.DownloadTask.java
/** * Executes the download in a separate thread *//*from w w w. j a va 2s . c om*/ public void run() { if (mInfo.mStatus != Downloads.STATUS_RUNNING) { mInfo.mStatus = Downloads.STATUS_RUNNING; ContentValues values = new ContentValues(); values.put(Downloads.COLUMN_STATUS, mInfo.mStatus); mContext.getContentResolver().update(mInfo.getAllDownloadsUri(), values, null, null); } else { if (Constants.LOGV) { Log.v(Constants.TAG, "download status is: " + mInfo.mStatus); } } Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); HttpStack client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } if (Build.VERSION.SDK_INT >= 9) { client = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html client = new HttpClientStack(AndroidHttpClient.newInstance(userAgent())); } boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); HttpGet request = new HttpGet(state.mRequestUri); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage()); finalStatus = error.mFinalStatus; // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex); finalStatus = Downloads.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { mNotifer.notifyDownloadSpeed(mInfo.mId, 0); if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { try { client.close(); client = null; } catch (IOException e) { e.printStackTrace(); finalStatus = Downloads.STATUS_UNKNOWN_ERROR; } } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.cancelTask(); } }
From source file:de.schildbach.wallet.ui.send.RaiseFeeDialogFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); viewModel = ViewModelProviders.of(this).get(ViewModel.class); viewModel.getDynamicFees().observe(this, new Observer<Map<FeeCategory, Coin>>() { @Override/*w w w.j a va 2 s . c o m*/ public void onChanged(final Map<FeeCategory, Coin> dynamicFees) { // We basically have to pay fee for two transactions: // The transaction to raise the fee of and the CPFP transaction we're about to create. final int size = transaction.getMessageSize() + 192; feeRaise = dynamicFees.get(FeeCategory.PRIORITY).multiply(size).divide(1000); updateView(); } }); final Bundle args = getArguments(); final byte[] txHash = (byte[]) args.getSerializable(KEY_TRANSACTION); transaction = checkNotNull(wallet.getTransaction(Sha256Hash.wrap(txHash))); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); }
From source file:de.schildbach.wallet.ui.BackupWalletToSeedDialogFragment.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final View view = LayoutInflater.from(activity).inflate(R.layout.backup_wallet_to_seed_dialog, null); seedView = (TextView) view.findViewById(R.id.backup_wallet_dialog_seed); privateKeyPasswordViewGroup = view.findViewById(R.id.backup_wallet_seed_private_key_password_group); privateKeyPasswordView = (EditText) view.findViewById(R.id.backup_wallet_seed_private_key_password); privateKeyBadPasswordView = (TextView) view.findViewById(R.id.backup_wallet_seed_private_key_bad_password); showMnemonicSeedButton = (Button) view.findViewById(R.id.backup_wallet_seed_private_key_enter); seedViewGroup = view.findViewById(R.id.backup_wallet_seed_group); writtenDown = (CheckBox) view.findViewById(R.id.backup_wallet_seed_private_key_written_down); fingerprintView = view.findViewById(R.id.fingerprint_view); privateKeyPasswordViewGroup.setVisibility(wallet.isEncrypted() ? View.VISIBLE : View.GONE); privateKeyPasswordView.addTextChangedListener(privateKeyPasswordListener); showMnemonicSeedButton.setOnClickListener(new OnClickListener() { @Override//from www .ja v a 2 s.c o m public void onClick(View v) { handleDecryptPIN(); } }); if (wallet.isEncrypted()) { backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); showPasswordViewGroup(true); updateView(false); } else { showMnemonicSeed(wallet.getActiveKeyChain().getSeed()); updateView(true); } final DialogBuilder builder = new DialogBuilder(activity); builder.setTitle(R.string.export_keys_dialog_title); builder.setView(view); builder.setCancelable(false); builder.setPositiveButton(R.string.button_dismiss, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (writtenDown.isChecked()) { config.disarmBackupSeedReminder(); } privateKeyPasswordView.removeTextChangedListener(privateKeyPasswordListener); if (getArguments().getBoolean(ARGS_IS_UPGRADING, false) && activity instanceof UpgradeWalletDisclaimerDialog.OnUpgradeConfirmedListener) { ((UpgradeWalletDisclaimerDialog.OnUpgradeConfirmedListener) activity).onUpgradeConfirmed(); } } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { initFingerprintHelper(); } return builder.create(); }
From source file:paulscode.android.mupen64plusae.task.ExtractTexturesService.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.pathHiResTexturesTask_title)) .setContentText(getString(R.string.toast_pleaseWait)).setContentIntent(pendingIntent); startForeground(ONGOING_NOTIFICATION_ID, builder.build()); }
From source file:io.n7.calendar.caldav.CalDAVService.java
@Override public void onCreate() { mCR = getContentResolver();/*from ww w . ja v a2s.com*/ // Check if there are any CalDAV accounts setup. // Check if the CalDAV calendars are present in the provider DB. If not, create. // Start Sync for all CalDAV calendars. mContext = this; HandlerThread thread = new HandlerThread("CalDAVService", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mServiceLooper = thread.getLooper(); mServiceHandler = new IncomingHandler(mServiceLooper); mMessenger = new Messenger(mServiceHandler); }
From source file:tree.love.providers.downloads.DownloadThread.java
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); try {/*from ww w . ja v a2 s . c om*/ runInternal(); } finally { mNotifier.notifyDownloadSpeed(mInfo.mId, 0); } }
From source file:com.cerema.cloud2.files.services.FileUploader.java
/** * Service initialization//www . j a va 2 s.c om */ @Override public void onCreate() { super.onCreate(); Log_OC.d(TAG, "Creating service"); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, this); mBinder = new FileUploaderBinder(); // add AccountsUpdatedListener AccountManager am = AccountManager.get(getApplicationContext()); am.addOnAccountsUpdatedListener(this, null, false); }
From source file:com.akop.bach.ImageCache.java
public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); while (true) { try {/*from w w w . j a va2s.com*/ mCurrentTask = mTasks.take(); if (mCurrentTask.alwaysRun || mListeners.contains(mCurrentTask.listener)) { mBusy = true; // Load bitmap Bitmap bmp = loadBitmapSynchronous(mCurrentTask.imageUrl, mCurrentTask.cachePol); if (mCurrentTask.alwaysRun || mListeners.contains(mCurrentTask.listener)) mCurrentTask.listener.onImageReady(mCurrentTask.id, mCurrentTask.param, bmp); mCurrentTask = null; } } catch (Exception e) { if (App.getConfig().logToConsole()) { App.logv("Error running task", e); e.printStackTrace(); } } mBusy = false; } }
From source file:com.ifeng.util.download.DownloadThread.java
/** * Executes the download in a separate thread *//*from w w w .j a va2 s . co m*/ @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); ProxyHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } client = new ProxyHttpClient(mContext, userAgent()); boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); HttpGet request = new HttpGet(state.mRequestUri.trim()); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through exc.printStackTrace(); } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.Impl.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage()); Log.w(Constants.TAG, "download error:", error); finalStatus = error.mFinalStatus; displayMsg(finalStatus, error.getMessage()); // mInfo.mFailedReason = mInfo.mFailedReason + " |||| " + Utils.getStackTraceString(error); // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex); Log.w(Constants.TAG, "download error:", ex); finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; displayMsg(finalStatus, ex.getMessage()); // mInfo.mFailedReason = mInfo.mFailedReason + "||||" + Utils.getStackTraceString(ex); // falls through to the code that reports an error } finally { if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { client.close(); client = null; } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mRedirectCount, state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); --DownloadService.mCurrentThreadNum; if (!Downloads.Impl.isStatusCompleted(finalStatus)) { mInfo.mHasActiveThread = false; } } }
From source file:de.pixart.messenger.ui.ScanActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); setContentView(R.layout.activity_scan); scannerView = findViewById(R.id.scan_activity_mask); previewView = findViewById(R.id.scan_activity_preview); previewView.setSurfaceTextureListener(this); cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND); cameraThread.start();// w w w . j a v a 2 s .co m cameraHandler = new Handler(cameraThread.getLooper()); }