本文整理汇总了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;
}