本文整理匯總了Java中android.os.Process.THREAD_PRIORITY_FOREGROUND屬性的典型用法代碼示例。如果您正苦於以下問題:Java Process.THREAD_PRIORITY_FOREGROUND屬性的具體用法?Java Process.THREAD_PRIORITY_FOREGROUND怎麽用?Java Process.THREAD_PRIORITY_FOREGROUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.os.Process
的用法示例。
在下文中一共展示了Process.THREAD_PRIORITY_FOREGROUND屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newThread
public static Thread newThread(String name, final int priority, Runnable r) {
return new Thread(r, "PTF-" + name) {
@Override
public void run() {
int priorityNew = priority;
if (priority > Process.THREAD_PRIORITY_LOWEST) {
priorityNew = Process.THREAD_PRIORITY_LOWEST;
} else if (priority < Process.THREAD_PRIORITY_FOREGROUND) {
priorityNew = Process.THREAD_PRIORITY_FOREGROUND;
}
Process.setThreadPriority(priorityNew);
super.run();
}
};
}
示例2: onCreate
@Override
public void onCreate() {
Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Native init
jni_init();
boolean pcap = prefs.getBoolean("pcap", false);
setPcap(pcap, this);
prefs.registerOnSharedPreferenceChangeListener(this);
Util.setTheme(this);
super.onCreate();
HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command", Process.THREAD_PRIORITY_FOREGROUND);
HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log", Process.THREAD_PRIORITY_BACKGROUND);
HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats", Process.THREAD_PRIORITY_BACKGROUND);
commandThread.start();
logThread.start();
statsThread.start();
commandLooper = commandThread.getLooper();
logLooper = logThread.getLooper();
statsLooper = statsThread.getLooper();
commandHandler = new CommandHandler(commandLooper);
logHandler = new LogHandler(logLooper);
statsHandler = new StatsHandler(statsLooper);
// Listen for power save mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) {
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
powersaving = pm.isPowerSaveMode();
IntentFilter ifPower = new IntentFilter();
ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
registerReceiver(powerSaveReceiver, ifPower);
registeredPowerSave = true;
}
// Listen for user switches
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
IntentFilter ifUser = new IntentFilter();
ifUser.addAction(Intent.ACTION_USER_BACKGROUND);
ifUser.addAction(Intent.ACTION_USER_FOREGROUND);
registerReceiver(userReceiver, ifUser);
registeredUser = true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Listen for idle mode state changes
IntentFilter ifIdle = new IntentFilter();
ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
registerReceiver(idleStateReceiver, ifIdle);
registeredIdleState = true;
}
// Listen for connectivity updates
IntentFilter ifConnectivity = new IntentFilter();
ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(connectivityChangedReceiver, ifConnectivity);
registeredConnectivityChanged = true;
// Listen for added applications
IntentFilter ifPackage = new IntentFilter();
ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED);
ifPackage.addDataScheme("package");
registerReceiver(packageChangedReceiver, ifPackage);
registeredPackageChanged = true;
// Setup house holding
Intent alarmIntent = new Intent(this, ServiceSinkhole.class);
alarmIntent.setAction(ACTION_HOUSE_HOLDING);
PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi);
}
示例3: init
/**
*
* @param threshold 設置輸出日誌的閾值,
* 比如設置為10,日誌會追蹤所有丟幀超過10幀的場景
* @param noSystemCode 堆棧是否需要含有Android係統代碼
* @return
*/
public Monitor init(int threshold,boolean noSystemCode) {
if (new Handler().getLooper() != Looper.getMainLooper()) {
throw new RuntimeException(" must init in Main thread !");
}
if (inited) {
return this;
}
if (threshold <= 0) {
threshold = 1;
}
this.threshold = threshold;
this.delay = delay * threshold;
HandlerThread mHandlerThread = new CheckerHandlerThread("monitor",
Process.THREAD_PRIORITY_FOREGROUND);
mHandlerThread.start();
mCheckerHandler = new Handler(mHandlerThread.getLooper(), this);
mMainHandler = new Handler(Looper.getMainLooper());
stackQueue = new QueueCache<>(threshold + 1);
mInfoConsumer = new InfoConsumer(noSystemCode);
mMainChoreographer = Choreographer.getInstance();
mMainCallback = new Choreographer.FrameCallback() {
@Override
public void doFrame(final long frameTimeNanos) {
final long delta = (frameTimeNanos - lastDoFrameTime) / 1000000;
if (lastDoFrameTime != 0 && delta > delay) {
//LogUtils.d("monitor", "main doFrame " + delta);
final long lastTime = lastDoFrameTime;
// 單線程操作 queue
mCheckerHandler.post(new Runnable() {
@Override
public void run() {
statisticsStack(frameTimeNanos / 1000000, delta, StackInfo.TYPE_CHECK);
processInfo(lastTime / 1000000, frameTimeNanos / 1000000);
}
});
}
lastDoFrameTime = frameTimeNanos;
if (mLoopFlag) {
mMainChoreographer.postFrameCallback(mMainCallback);
}
}
};
inited = true;
return this;
}