问题

I know that some peoples view is that you should not create persistent services.

But for those of us that want to increase our knowledge, how does one go about creating one in theory?

I have been playing around, and noticed that services that use startForeground are killed in low memory situations.

I have seen a, now deprecated, permission PERSISTENT_ACTIVITY, but that didn't do much.

So what is the secret?

回答1:

You can only make your service persistent if you are developing system apps. These services will be basically un-killable, and are labeled as "PERS" in the output of the "adb shell dumpsys activity" command. It's not very well documented, so I did a quick write-up on Persistent services in Android...hopefully it will help some people out.

But for non-system apps, startForeground is your best option.

回答2:

There is absolutely no way of preventing the OS from killing your service.

来源:https://stackoverflow.com/questions/4708827/persistent-service

android service设置persistent,Persistent service相关推荐

  1. [转] Android开发之如何保证Service不被杀掉(broadcast+system/app)

    转发:原文链接http://blog.csdn.net/mad1989/article/details/22492519 序言 最近项目要实现这样一个效果:运行后,要有一个service始终保持在后台 ...

  2. Android开发之如何保证Service不被杀掉(broadcast+system/app)

    Android开发之如何保证Service不被杀掉(broadcast+system/app) 序言 最近项目要实现这样一个效果:运行后,要有一个service始终保持在后台运行,不管用户作出什么操作 ...

  3. Android Service(一) Service初识

    在开发应用中,或多或少都会遇到Service有关知识.今天就来分析Service的使用. 一.概述. 首先看看官网是如何描述的. A Service is an application compone ...

  4. 【Android 进程保活】应用进程拉活 ( 系统 Service 机制拉活 | Service 组件 onStartCommand 方法分析 | 源码资源 )

    文章目录 一. Service 组件 onStartCommand 方法分析 1. onStartCommand 函数返回值分析 2. onStartCommand 函数 START_STICKY_C ...

  5. Android init.rc如何启动service去执行sh脚本

    在Android开发中经常会遇到,在应用层想去执行一个脚本来完成某些底层相关的操作,但在应用层又没有root权限. 所以,老大给出一种方法完美解决此问题,又把上层和底层进行了隔离,非常好的策略. 1. ...

  6. Android开发之如何保证Service不被杀掉(前台服务)

    序言 最近项目要实现这样一个效果:运行后,要有一个service始终保持在后台运行,不管用户作出什么操作,都要保证service不被kill.参考了现今各种定制版的系统和安全厂商牛虻软件,如何能保证自 ...

  7. android进程守护 失效,保持Service不被Kill掉的方法--双Service守护 Android实现双进程守护 1...

    本文分为两个部分,第一部分为双Service守护,第二部分为双进程守护 第一部分: 一.Service简介:Java.lang.Object ?Android.content.Context ?and ...

  8. Android开发之使用Web Service进行网络编程

    使用Web Service进行网络编程 Android应用通常都是运行在手机平台上,手机系统的硬件资源是有限的,不管是存储能力还是计算能力都有限,在Android系统上开发.运行一些单用户.小型应用是 ...

  9. Android创建前台运行的Service

    Service如果要防止尽可能不被系统杀掉,需要设置为在前台运行. 由于设置前台运行service的方法在2.0之前和2.0之后有所变化. 所以需要根据不同的版本进行区分:或者完全使用反射机制来处理, ...

  10. android学习十八(Service服务的基本用法)

    定义一个服务 在项目中定义一个服务,新建一个ServiceTest项目,然后在这个项目中新增一个名为MyService的类,并让它继承自Service,完成后的代码如下所示: package com. ...

最新文章

  1. java动态代理_Java代理模式及动态代理详解
  2. MVC与MVP简单对比
  3. 携程开源Redis多数据中心解决方案-XPipe
  4. Oracle一致性读(Consistent Read)的原理
  5. vuejs项目开发环境搭建(ESlint安装)
  6. 深入理解include预编译原理
  7. Windows下架设SVN服务
  8. 自动创建日期文件并写入数据python脚本
  9. C++ UPD广播异步发包工具
  10. python爬虫——使用bs4爬取搜狗微信文章
  11. 阿里云负载均衡SLB简介
  12. 免费帝国CMS发布插件
  13. (Java)输入一个字母,若是小写字母,则变为大写输出,否则,原样输出
  14. 关于Qt作为第三方库,QGIS二次开发作为第三方库,Qt ui编译的一些问题
  15. android获取uid,Android获得UID的办法
  16. 耗电排行Android,揪出Android手机电老虎!耗电应用排行
  17. python缩进可以用在任何语句之后_Python程序中,缩进表达所属关系,在缩进的前一行最后,需要使用符号 Python 语句中增...
  18. idea如何启动vue项目
  19. C语言:链表实现二进制数加1运算
  20. PSpice 常见问题

热门文章

  1. Bzoj1972: [Sdoi2010]猪国杀 题解(大模拟+耐心+细心)
  2. java实现路由器重启_java 重启路由器
  3. 燕东微通过注册:预计年营收超20亿 亦庄国投与京东方是股东
  4. fatal error C1083,但文件确实却在,也能加载
  5. 微信可以修改微信号了
  6. 理解复数域上的向量空间
  7. php日期自动加一天,php 当前日期加一天和指定日期加一天
  8. 基于@Aspect实现AOP的两种方式
  9. 计算机数据计量单位换算
  10. 笔记本电脑触摸板的使用