博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android防止进程被第三方软件杀死
阅读量:7048 次
发布时间:2019-06-28

本文共 1229 字,大约阅读时间需要 4 分钟。

http://blog.csdn.net/wangliang198901/article/details/12342845

http://stackoverflow.com/questions/3856767/android-keeping-a-background-service-alive-preventing-process-death

http://www.cnblogs.com/cc-Cheng/p/3146143.html

 

调用

@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.source_activity);
startService(new Intent(this, RunService.class));
}

 

定义

public class RunService extends Service {

@Override

public void onCreate() {
sendNotification();
}

private void sendNotification() {

Log.i("ss","____________________________sendNotification");
Notification notification = new Notification();
Intent notificationIntent = new Intent(this, ScreenRecorderActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, "3DHome", "Welcome to 3DHome !", pendingIntent);
try {
startForeground(12314, notification);
} catch (Exception e) {

}

}
@Override
public void onDestroy() {
stopForeground(true);
}

@Override

public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}

分类: 
本文转自wanqi博客园博客,原文链接:http://www.cnblogs.com/wanqieddy/p/4585909.html,如需转载请自行联系原作者
你可能感兴趣的文章
iOS 百度地图大头针使用
查看>>
1118: 零起点学算法25——求两点之间的距离
查看>>
delegate代理设计模式
查看>>
花10分钟搞懂开源框架吧 - 【NancyFx.Net】
查看>>
busybox的使用
查看>>
GridView(网格视图)+MotionEvent(触控事件)实现可以拖动排序的网格图
查看>>
jq实现全选或者全不选
查看>>
牛人博客
查看>>
TOJ 4383: n % ( pow( p , 2) ) ===0
查看>>
vue2+vuex+vue-router 快速入门(三) vue 实例介绍
查看>>
[]APC001
查看>>
linux笔记_20150825_linux有什么好处
查看>>
各种实用工具的使用 学习
查看>>
MarkLight
查看>>
Game Physics Cookbook (Gabor Szauer 著)
查看>>
显示/隐藏Mac下的隐藏文件
查看>>
开启mysql远程连接
查看>>
iBatis.Net系列(四)-properties.config
查看>>
菜鸟vimer成长记——第2.2章、visual模式
查看>>
学城项目知识点整理及源码
查看>>