当前位置:网站首页>Start background services across processes
Start background services across processes
2022-07-30 19:20:00 【rookie xiaowang】
public class MyService extends Service {private static final String CHANNEL_ID = "100";private static final String CHANNEL_NAME = "APK1";public MyService() {}@Overridepublic IBinder onBind(Intent intent) {// TODO: Return the communication channel to the service.throw new UnsupportedOperationException("Not yet implemented");}@Overridepublic 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);}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Timer timer = new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {Intent intent = new Intent();intent.setAction("android.intent.action.START_SERVICE");The first parameter is the package name and the second parameter is the package name plus the class nameintent.setComponent(new ComponentName("com.example.apk2","com.example.apk2.MyService"));intent.putExtra("msg","Start service across processes");startForegroundService(intent);Log.e(getClass().getName(), "startService end");}},30 * 1000);return super.onStartCommand(intent, flags, startId);}}边栏推荐
- 部分分类网络性能对比
- MindSpore:【JupyterLab】按照新手教程训练时报错
- The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
- NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
- 7.29模拟赛总结
- Spark学习:编译Spark项目时遇到的报错
- scrapy基本使用
- 第一次进入小程序判断
- 【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点
- MongoDB打破了原则引入SQL?
猜你喜欢

VS Code connects to SQL Server

Basic use of scrapy

Golang logging library zerolog use record

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

CIMC Shilian Dafeitong is the global industrial artificial intelligence AI leader, the world's top AI core technology, high generalization, high robustness, sparse sample continuous learning, industri

MindSpore:【JupyterLab】按照新手教程训练时报错

Does the satellite phone communicate directly with the satellite or through a ground station?

深入浅出边缘云 | 3. 资源配置

MindSpore:对image作normalize的目的是什么?

Swiper轮播图片并播放背景音乐
随机推荐
natural language processing nltk
AI Basics: Graphical Transformer
Chapter 14 Type Information
跨进程启动后台服务
MindSpore:【Resolve node failed】解析节点失败的问题
kotlin by lazy
尊重客观事实
Recommendation | People who are kind to you, don't repay them by inviting them to eat
解决终极bug,项目最终能顺利部署上线。
[Summary] 1396- 60+ VSCode plugins to create a useful editor
监听开机广播
MindSpore:【JupyterLab】查看数据时报错
高并发秒杀项目总结
荐号 | 对你有恩的人,不要请吃饭来报答
ResNet18-实现图像分类
Go 系统收集
第一次进入小程序判断
Google's AlphaFold claims to have predicted almost every protein structure on Earth
NXP IMX8QXP replacement DDR model operation process
NXP IMX8QXP更换DDR型号操作流程