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

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

vxe-table实现复选框鼠标拖动选中

【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list

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

After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...

Basic use of scrapy

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

部分分类网络性能对比

Critical Reviews | 南农邹建文组综述全球农田土壤抗生素与耐药基因分布

redis
随机推荐
Recommended Books | Recommend 3 database books with rave reviews
ROS 环境使用第三方动态链接库(.so)文件
第4章 控制执行流程
WeChat Mini Program Cloud Development | Urban Information Management
SwiftUI iOS 精品开源项目之 完整烘焙食品菜谱App基于SQLite(教程含源码)
3D机器视觉厂商的场景争夺战役
电脑死机的时候,发生了什么?
OSPF详解(3)
单例模式 (Singleton)
Pytorch基础--tensorboard使用(一)
Scala学习:类和对象
SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
不同的路径依赖
node封装一个控制台进度条插件
natural language processing nltk
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
Node encapsulates a console progress bar plugin
深化校企合作 搭建技术技能人才成长“立交桥”
Immersive experience iFLYTEK 2022 Consumer Expo "Official Designated Product"
Spark学习:编译Spark项目时遇到的报错