当前位置:网站首页>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);}}
边栏推荐
- 牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)
- 7.29模拟赛总结
- 看完《二舅》,我更内耗了
- 第14章 类型信息
- VBA runtime error '-2147217900 (80040e14): Automation error
- Go system collection
- SimpleOSS third-party library libcurl and engine libcurl error solution
- 【PHPWord】Quick Start of PHPWord in PHPOffice Suite
- MySql中@符号的使用
- vxe-table实现复选框鼠标拖动选中
猜你喜欢
开心的聚餐
JS提升:Promise中reject与then之间的关系
Alibaba Cloud Martial Arts Headline Event Sharing
【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点
VS Code connects to SQL Server
scrapy基本使用
【Prometheus】Prometheus联邦的一次优化记录[续]
谷歌AlphaFold近日宣称预测出地球上几乎所有蛋白质结构
The Meta metaverse division lost 2.8 billion in the second quarter!Still want to keep betting?Metaverse development has yet to see a way out!
防抖和节流有什么区别,分别用于什么场景?
随机推荐
Golang logging library zerolog use record
Vulkan开启特征(feature)的正确姿势
VBA 连接Access数据库和Excle
尊重客观事实
Perfectly Clear QuickDesk & QuickServer图像校正优化工具
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
Scala学习:breakable
Correct pose of Vulkan open feature
kotlin的by lazy
Go system collection
看完《二舅》,我更内耗了
What is the difference between a cloud database and an on-premises database?
MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
【每日一道LeetCode】——191. 位1的个数
OneFlow源码解析:Op、Kernel与解释器
启动前台Activity
又一家公司面试的内容
Delay queue optimization (2)
Read the "Language Model" in one article
Talking about Contrastive Learning (Contrastive Learning) the first bullet