当前位置:网站首页>跨进程启动后台服务
跨进程启动后台服务
2022-07-30 18:58:00 【菜鸟xiaowang】
public class MyService extends Service {
private static final String CHANNEL_ID = "100";
private static final String CHANNEL_NAME = "APK1";
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
super.onCreate();
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
Notification notification = new Notification.Builder(getApplicationContext(), CHANNEL_ID).build();
startForeground(1, notification);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setAction("android.intent.action.START_SERVICE");
第一个参数是包名 第二个参数是包名加类名
intent.setComponent(new ComponentName("com.example.apk2","com.example.apk2.MyService"));
intent.putExtra("msg","跨进程启动service");
startForegroundService(intent);
Log.e(getClass().getName(), "startService end");
}
},30 * 1000);
return super.onStartCommand(intent, flags, startId);
}
}
边栏推荐
- What is the value of biomedical papers? How to translate the papers into Chinese and English?
- The use of terminal split screen tool Terminalx
- ROS 环境使用第三方动态链接库(.so)文件
- Range.CopyFromRecordset 方法 (Excel)
- "Ruffian Heng Embedded Bimonthly" Issue 59
- 解决终极bug,项目最终能顺利部署上线。
- Deepen school-enterprise cooperation and build an "overpass" for the growth of technical and skilled talents
- DTSE Tech Talk丨第2期:1小时深度解读SaaS应用系统设计
- Basic use of scrapy
- 深入浅出边缘云 | 3. 资源配置
猜你喜欢
Deepen school-enterprise cooperation and build an "overpass" for the growth of technical and skilled talents
Spark学习:用spark实现ETL
MySql中@符号的使用
6块钱1斤,日本公司为何来中国收烟头?
Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!
经济新闻:错误# 15:初始化libiomp5md。dll,但发现libiomp5md。已经初始化dll。解决方法
(2022杭电多校四)1001-Link with Bracket Sequence II(区间动态规划)
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
The large-scale application of artificial intelligence AI products in industrial-grade mature shipping ports of CIMC World Lianda will create a new generation of high-efficiency smart ports and innova
scrapy基本使用
随机推荐
跨域问题的解决方法
荐号 | 对你有恩的人,不要请吃饭来报答
6块钱1斤,日本公司为何来中国收烟头?
积性函数
深入浅出边缘云 | 3. 资源配置
Chapter 14 Type Information
延时队列优化 (2)
二分答案裸题(加一点鸽巢原理)
AI基础:图解Transformer
运营 23 年,昔日“国内第一大电商网站”黄了...
Scala学习:类和对象
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
Scrapy framework is introduced
CCNA-ACL(访问控制列表)标准ACL 扩展ACL 命名ACL
CCNA-子网划分(VLSM)
OSPF详解(4)
requet.getHeader(“token“) 为null
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
kotlin by lazy
CCNA-NAT协议(理论与实验练习)