android应用多线程守护让你非常难杀死它
1、android 应用开启后启动一个服务
public class TestserviceActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("activity执行的线程id:"+ Thread.currentThread().getName() +"--"+
Thread.currentThread().getId());
System.out.println("activity的进程id:"+android.os.Process.myPid());
Intent intent = new Intent(this,Service1.class);
startService(intent);
}
}
2、第一个服务
public class Service1 extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
System.out.println("服务1 被开启");
System.out.println("服务执行的线程id:"+ Thread.currentThread().getName() +"--"+
Thread.currentThread().getId());
System.out.println("服务的进程id:"+android.os.Process.myPid());
super.onCreate();
}
@Override
public void onDestroy() {
Intent intent = new Intent(this,Service2.class);
startService(intent);
super.onDestroy();
}
}
3、第2个服务
public class Service2 extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
System.out.println("服务2 被开启");
super.onCreate();
}
@Override
public void onDestroy() {
Intent intent = new Intent(this,Service1.class);
startService(intent);
super.onDestroy();
}
}
4、清单文件里
<service android:name=".Service1"
android:process="cn.it.yqq"
></service>
<service android:name=".Service2"></service>
android应用多线程守护让你非常难杀死它的更多相关文章
- Android网络多线程断点续传下载
本示例介绍在Android平台下通过HTTP协议实现断点续传下载. 我们编写的是Andorid的HTTP协议多线程断点下载应用程序.直接使用单线程下载HTTP文件对我们来说是一件非常简单的事.那么,多 ...
- 教你如何在 Android 使用多线程下载文件
# 教你如何在 Android 使用多线程下载文件 前言 在 Android 日常开发中,我们会经常遇到下载文件需求,这里我们也可以用系统自带的 api DownloadManager 来解决这个问题 ...
- Android进阶——多线程系列之Thread、Runnable、Callable、Future、FutureTask
多线程一直是初学者最抵触的东西,如果你想进阶的话,那必须闯过这道难关,特别是多线程中Thread.Runnable.Callable.Future.FutureTask这几个类往往是初学者容易搞混的. ...
- 13、Android的多线程与异步任务
课程目标:学习Android中异步操作的三大方式 重点难点:Handler与线程的关系 Handler消息队列的实现 考核目标: 使用Handler是异步的,它会建立新线程么? no Handle ...
- Android中多线程下载列表的封装实现(含进度反馈)
来源:http://blog.csdn.net/u011638883/article/details/17347015 实现了一下Android中的文件多线程下载模块,支持自定义线程数.断点续传.下载 ...
- java线程 - 多线程 - 守护线程
1.多线程执行者/处理类 都是Runnable的实现类(如自定义类实现Runnable 或 java原生的Thread.FutureTask),但最后都必须封装成Thread线程类由Thread.st ...
- android开发--多线程
android中的几种多线程实现方式: 1)Activity.runOnUiThread(Runnable) 2)View.post(Runnable) ;View.postDelay(Runnabl ...
- Android handle 多线程练习
Android handle <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&quo ...
- (原创)android Sqlite多线程访问异常解决方案
在开发Android的程序的时候sqlite数据库是经常用到的:在多线程访问数据库的时候会出现这样的异常:java.lang.IllegalStateException: Cannot perform ...
随机推荐
- Educational Codeforces Round 30 A[水题/数组排序]
A. Chores time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- [BZOJ4337][BJOI2015]树的同构(树的最小表示法)
4337: BJOI2015 树的同构 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1023 Solved: 436[Submit][Status ...
- 【强连通分量缩点】【记忆化搜索】bzoj1589 [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
缩成DAG f(i)表示以i为起点的最长路 #include<cstdio> #include<cstring> #include<algorithm> #incl ...
- 在iPhone上取消APP订阅
1.在iPhone上打开APP Store,在精品推荐那个界面滚动到底部. 2.点击Apple ID那一栏,如图: 3.点击查看Apple ID,如图: 4.点击管理,如图: 5.关掉此选项,如图: ...
- Android Studio 生成aar包多Module引用问题
问题描述: 有个arr文件被放到Module A中引用,现在Module B又依赖了Module A,则在编译过程中会发生错误,Module B找不到aar文件. 解决办法: 使用相对路径来找到这个a ...
- Go beego框架使用笔记(一)
Beego介绍 beego我认为是go初学者比较容易上手的一门MVC Web框架.简单易懂,最重要的一点就是提供了中文文档,这对于我这种英语能力比较差的人来说就是福音. beego的官网上是这么介绍b ...
- C# 7 新特性-2
在之前的C# 7 新特性博客中,我们谈到了Tuples,Record Type和Pattern Matching.这些都是C#新特性中最可能出现的.在本博客中,我们会提到更多的一些特性,虽然这些特性不 ...
- Easyui datagrid 隐藏多选框 checkbox
在加载 表格的时候添加事件:onLoadSuccess 在事件中写入下面句,用空代替原有HTML 达到取消效果. $(".datagrid-header-check").html( ...
- 10个常用的ps命令总结,参数
Linux系统中10个常用的ps命令总结 PS 命令是什么 查看它的man手册可以看到,ps命令能够给出当前系统中进程的快照.它能捕获系统在某一事件的进程状态.如果你想不断更新查看的这个状态,可以使用 ...
- Flask+uwsgi+Nginx环境搭建
开源软件准备需要的软件列表:setuptools-33.1.1.zipPython-2.7.13.tgzpip-9.0.1.tar.gznginx-1.10.3.tar.gz软件统一上传到/usr/l ...