当前位置: 首页 > news >正文

凡科做的网站要收费吗/网站怎么进入

凡科做的网站要收费吗,网站怎么进入,公安网站开发功能介绍,男女做暧暧观看免费网站一文读懂Android的进程发布时间:2020-11-07 17:13:08来源:亿速云阅读:73这篇文章将为大家详细讲解有关一文读懂Android的进程,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关…

一文读懂Android的进程

发布时间:2020-11-07 17:13:08

来源:亿速云

阅读:73

这篇文章将为大家详细讲解有关一文读懂Android的进程,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

多进程

如果需要的时候,app可以创建多进程。

在进程里面

各类组件元素的清单文件条目 、 、 和

— 均支持 android:process 属性,此属性可以指定该组件应在哪个进程运行。

默认进程就是主进程。其他进程一般来说都是子进程。

2个activity在不同的进程里面,可以刷新UI吗?

android:process=":progressb"/>

测试结果:ActivityProgressB可以正常显示。这个其实很好理解,如果你打开系统相机页面,那个activity肯定与你的app不再一个进程,但是他可以很顺利的打开,所以可以支持。

保活

OOM_ADJ

   referrerpolicy=

这个就是oom 回kill进程的优先级。

进程kill的方式场景接口范围LowMemoryKillerLowMemoryKiller从进程的优先级依次kill,释放内存

三方kill(无root)killbackgroundprogerssskill oom_adj>4

三方kill(有root)forcestop or kill理论上所有,一般是非系统和可见进程

厂商kill功能force stop or kill理论上所有,包括native

进程保活的目的,就是提供进程的优先级,降低进程被kill的概率。

保活的套路

开启1个像素的activity2020-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以后,不允许后台进程启动后台页面了。也就是想启动一个前台页面

使用前台服务

package com.demanmath.androidms.androidsample

import android.annotation.TargetApi

import android.app.Notification

import android.app.NotificationChannel

import android.app.NotificationManager

import android.app.Service

import android.content.Context

import android.content.Intent

import android.os.Build

import android.os.Handler

import android.os.IBinder

import androidx.core.app.NotificationCompat

import com.demanmath.androidms.AppLog

import 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

//发送与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 NotificationManager

manager.cancel(NOTIFICATION_ID)

stopSelf()

}, 100)

}

}

}

但是androidQ开始以后,禁止后台进程开启前台进程,这个也是android为了省电考虑的。

多进程相互唤醒

这个就是每个app,其多个进程,如果比kill掉了,可以通过另一个唤起。从上面的前台service的功效有些类似。

同样的问题,android Q以后无效。

JobSchedule

package com.demanmath.androidms.jobservice

import android.app.job.JobParameters

import android.app.job.JobService

import android.content.Intent

import android.os.Handler

import android.os.Message

import android.widget.Toast

import 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()

//请注意,我们手动调用了jobFinished方法。

//当onStartJob返回true的时候,我们必须手动调用jobFinished方法

//否则该应用中的其他job将不会被执行

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.jobservice

import android.app.job.JobInfo

import android.app.job.JobScheduler

import android.content.ComponentName

import android.content.Context

import 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的进程就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

http://www.lbrq.cn/news/1411345.html

相关文章:

  • h5网站开发模板/百度收录入口提交
  • 中国在数码网站注册域名好 gt/安卓优化大师hd
  • hao123浏览器下载安装/seo页面链接优化
  • 搭建网站怎么做/找平台推广
  • 网站数据库如何建设/seo数据监控平台
  • 网页设计网站建设/爱站小工具
  • 专业网站开发报价/站长seo
  • 自己免费做网站的流程/搜索引擎优化主要包括
  • 做平台的网站有哪些功能/seo是什么软件
  • 如何删除网站后台的文章/网络推广营销方案免费
  • 网站开发 网站建设/上海专业的seo公司
  • wordpress网站显示不全/seo标题优化是什么意思
  • 高端网站建设 选择磐石网络/免费发外链平台
  • wordpress制作客户端/如何点击优化神马关键词排名
  • 网站海外推广哪家好/2022新闻大事件摘抄
  • 长沙小升初有什么做试卷的网站/网站制作公司排行榜
  • 一个虚拟主机如何做两个网站/推广之家官网
  • 济南网站建设企业/搜索推广开户
  • wordpress 多站点开启/优化设计七年级上册数学答案
  • php语言 网站建设/写文章在哪里发表挣钱
  • 昆明云南微网站/seo基础优化包括哪些内容
  • 丰台青岛网站建设/网站排名优化服务公司
  • 岳池县网站建设/网上营销的方式
  • 免费手机网站空间/在线咨询
  • 电子商务网站开发常用工具/卖友情链接的哪来那么多网站
  • 德清县建设银行官方网站/真正的免费建站在这里
  • 在阿里云做视频网站需要什么/不受国内限制的搜索引擎
  • 关于网站开发相关法律条款/零基础怎么做电商
  • 苏州有哪些做网站公司好/企业建站流程
  • 加若格网站做么样/无锡百度推广代理公司
  • 从哲学(业务)视角看待数据挖掘:从认知到实践的螺旋上升
  • 理解AQS的原理并学习源码
  • OpenAL技术详解:跨平台3D音频API的设计与实践
  • Spring Boot 实用小技巧:多级缓存(Caffeine + Redis)- 第545篇
  • metasploit 框架安装更新遇到无法下载问题如何解决
  • 39.离散化与哈希