当前位置:网站首页>跨进程启动后台服务
跨进程启动后台服务
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);
}
}边栏推荐
猜你喜欢

OneFlow source code analysis: Op, Kernel and interpreter

基于inquirer封装一个控制台文件选择器

6块钱1斤,日本公司为何来中国收烟头?

Scrapy framework is introduced

沉浸式体验科大讯飞2022消博会“官方指定产品”

微信小程序云开发 | 城市信息管理
![[Prometheus] An optimization record of the Prometheus federation [continued]](/img/5d/56e171b7a02584337a0cfe5c731fb2.png)
[Prometheus] An optimization record of the Prometheus federation [continued]

自然语言处理nltk

电脑死机的时候,发生了什么?

【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest
随机推荐
高精度加法
[Use of Qt Designer tool]
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
AWS 控制台
Mysql执行原理剖析
尊重客观事实
积性函数
第14章 类型信息
NC | 西湖大学陶亮组-TMPRSS2“助攻”病毒感染并介导索氏梭菌出血毒素的宿主入侵...
Chapter 4 Controlling the Execution Flow
MYSQL (Basic) - An article takes you into the wonderful world of MYSQL
2种手绘风格效果比较,你更喜欢哪一种呢?
电脑死机的时候,发生了什么?
【刷题篇】计算质数
Codeblocks + Widgets 创建窗口代码分析
CCNA-ACL(访问控制列表)标准ACL 扩展ACL 命名ACL
6块钱1斤,日本公司为何来中国收烟头?
redis
Scrapy framework is introduced
WeChat Mini Program Cloud Development | Urban Information Management