国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

詳解Android 進(jìn)程

瀏覽:83日期:2022-09-22 18:41:25

多進(jìn)程

如果需要的時候,app可以創(chuàng)建多進(jìn)程。

在進(jìn)程里面

各類組件元素的清單文件條目 、 、 和— 均支持 android:process 屬性,此屬性可以指定該組件應(yīng)在哪個進(jìn)程運行。

默認(rèn)進(jìn)程就是主進(jìn)程。其他進(jìn)程一般來說都是子進(jìn)程。

2個activity在不同的進(jìn)程里面,可以刷新UI嗎?

<activity android:name='.androidsample.ActivityProgressB' android:process=':progressb'/>

測試結(jié)果:ActivityProgressB可以正常顯示。這個其實很好理解,如果你打開系統(tǒng)相機(jī)頁面,那個activity肯定與你的app不再一個進(jìn)程,但是他可以很順利的打開,所以可以支持。

保活

OOM_ADJ

詳解Android 進(jìn)程

這個就是oom 回kill進(jìn)程的優(yōu)先級。

進(jìn)程kill的方式

場景 接口 范圍 LowMemoryKiller LowMemoryKiller 從進(jìn)程的優(yōu)先級依次kill,釋放內(nèi)存 三方kill(無root) killbackgroundprogersss kill oom_adj>4 三方kill(有root) forcestop or kill 理論上所有,一般是非系統(tǒng)和可見進(jìn)程 廠商kill功能 force stop or kill 理論上所有,包括native

進(jìn)程保活的目的,就是提供進(jìn)程的優(yōu)先級,降低進(jìn)程被kill的概率。

保活的套路

開啟1個像素的activity

2020-08-14 14:29:48.630 1164-8504/system_process W/ActivityTaskManager: Background activity start [callingPackage: com.demanmath.androidms; callingUid: 10398; isCallingUidForeground: false; isCallingUidPersistentSystemProcess: false; realCallingUid: 10398; isRealCallingUidForeground: false; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: null; isBgStartWhitelisted: false; intent: Intent { flg=0x10000000 cmp=com.demanmath.androidms/.androidsample.LiveActivity }; callerApp: ProcessRecord{a168b71 2429:com.demanmath.androidms/u0a398}]

在android Q以后,不允許后臺進(jìn)程啟動后臺頁面了。也就是想啟動一個前臺頁面

使用前臺服務(wù)

package com.demanmath.androidms.androidsampleimport android.annotation.TargetApiimport android.app.Notificationimport android.app.NotificationChannelimport android.app.NotificationManagerimport android.app.Serviceimport android.content.Contextimport android.content.Intentimport android.os.Buildimport android.os.Handlerimport android.os.IBinderimport androidx.core.app.NotificationCompatimport com.demanmath.androidms.AppLogimport com.demanmath.androidms.R/** * @author DemanMath * @date 2020/8/14 * */class KeepLiveService:Service() { val NOTIFICATION_ID = 0x11 val NOTIFICATION_CHANNEL_ID = 'demanmathId' val channelName = 'My Background Service' companion object { const val NOTIFICATION_ID = 0x11 } override fun onBind(intent: Intent?): IBinder? { return null } override fun onCreate() { super.onCreate() if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { startForeground(NOTIFICATION_ID, Notification()) } else { startMyOwnForeground() startService(Intent(this, InnerService::class.java)) } } @TargetApi(value = Build.VERSION_CODES.O) private fun startMyOwnForeground() { AppLog.d() val chan = NotificationChannel( NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE ) chan.lockscreenVisibility = Notification.VISIBILITY_PRIVATE val manager = (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) manager.createNotificationChannel(chan) val notificationBuilder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) val notification = notificationBuilder.setOngoing(true) .setSmallIcon(R.drawable.ic_launcher_background) .setContentTitle('App is running in background') .setPriority(NotificationManager.IMPORTANCE_MIN) .setCategory(Notification.CATEGORY_SERVICE) .build() startForeground(NOTIFICATION_ID, notification) } class InnerService : Service() { override fun onBind(intent: Intent): IBinder? { return null } override fun onCreate() { super.onCreate() //使用channeId & channelName //發(fā)送與KeepLiveService中ID相同的Notification,然后將其取消并取消自己的前臺顯示// val builder: Notification.Builder = Notification.Builder(this)// builder.setSmallIcon(R.mipmap.ic_launcher)// startForeground(NOTIFICATION_ID, builder.build()) Handler().postDelayed(Runnable {stopForeground(true)val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManagermanager.cancel(NOTIFICATION_ID)stopSelf() }, 100) } }}

但是androidQ開始以后,禁止后臺進(jìn)程開啟前臺進(jìn)程,這個也是android為了省電考慮的。

多進(jìn)程相互喚醒

這個就是每個app,其多個進(jìn)程,如果比kill掉了,可以通過另一個喚起。從上面的前臺service的功效有些類似。

同樣的問題,android Q以后無效。

JobSchedule

package com.demanmath.androidms.jobserviceimport android.app.job.JobParametersimport android.app.job.JobServiceimport android.content.Intentimport android.os.Handlerimport android.os.Messageimport android.widget.Toastimport com.demanmath.androidms.AppLog/** * @author DemanMath * @date 2020/8/20 * */class JobDemoService:JobService() { override fun onCreate() { super.onCreate() AppLog.i() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { AppLog.i() return super.onStartCommand(intent, flags, startId) } private var mHandler = object:Handler(){ override fun handleMessage(msg: Message) { AppLog.i() Toast.makeText(applicationContext,'JobService task running', Toast.LENGTH_SHORT ).show() //請注意,我們手動調(diào)用了jobFinished方法。 //當(dāng)onStartJob返回true的時候,我們必須手動調(diào)用jobFinished方法 //否則該應(yīng)用中的其他job將不會被執(zhí)行 jobFinished(msg.obj as JobParameters, false) } } override fun onStartJob(params: JobParameters?): Boolean { AppLog.i() mHandler.sendMessage(Message.obtain(mHandler,1,params)) return true } override fun onStopJob(params: JobParameters?): Boolean { AppLog.i() mHandler.removeMessages(1) return false }}

package com.demanmath.androidms.jobserviceimport android.app.job.JobInfoimport android.app.job.JobSchedulerimport android.content.ComponentNameimport android.content.Contextimport com.demanmath.androidms.AppLog/** * @author DemanMath * @date 2020/8/20 * */class JobHelper(var context: Context) { lateinit var jobScheduler:JobScheduler fun startJob(){ AppLog.i() jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler var builder = JobInfo.Builder(1, ComponentName(context.packageName,JobDemoService::class.java.name))// builder.setBackoffCriteria(1000L,JobInfo.BACKOFF_POLICY_LINEAR) var boolean = jobScheduler.schedule(builder.build()) AppLog.i(boolean.toString()) }}

以上就是詳解Android 進(jìn)程的詳細(xì)內(nèi)容,更多關(guān)于Android 進(jìn)程的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 日韩中文字幕免费在线观看 | 一区二区三区视频在线观看 | 免费播放欧美毛片欧美aaaaa | 日韩一级高清 | 三级三级三级全黄 | 欧美成人精品福利在线视频 | 欧美在线一区二区三区欧美 | 亚洲精品国产第一区二区多人 | 国产成人精品亚洲77美色 | 国产99视频精品免费视频免里 | 欧美野外性xxxxfeexxxxx | 国产在线高清不卡免费播放 | 国产精品亚洲玖玖玖在线靠爱 | 国产精品二区高清在线 | 自拍偷自拍亚洲精品10p | 九九热视频精品在线观看 | 欧美性f| 国产一区在线播放 | 男人的天堂久久精品激情 | 天天看片天天爽_免费播放 天天看夜夜 | 91青草久久久久久清纯 | 欧美专区视频 | 免费国产成人手机在线观看 | selaoban在线视频免费精品 | 美女让我桶 | 国产成人免费网站在线观看 | 在线免费一区二区 | 明星国产欧美日韩在线观看 | 看久久| 草草影院国产第一页 | 婷婷国产成人久久精品激情 | 在线观看欧美亚洲日本专区 | 国产欧美日韩在线 | 国产91精选在线观看网站 | 欧美成人免费观看bbb | 日本免费一区二区三区三州 | 亚洲欧美日韩综合二区三区 | 久久中文字幕久久久久91 | 中文字幕一区二区精品区 | 欧美日韩视频在线第一区 | 美女很黄很黄免费 |