当前位置:网站首页>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);}}边栏推荐
猜你喜欢
![[Summary] 1396- 60+ VSCode plugins to create a useful editor](/img/e4/65e55d0e4948c011585b72733d4d19.jpg)
[Summary] 1396- 60+ VSCode plugins to create a useful editor

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

MongoDB打破了原则引入SQL?

MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to

牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)

SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)

Swiper轮播图片并播放背景音乐

延时队列优化 (2)

AI Basics: Graphical Transformer

VBA 连接Access数据库和Excle
随机推荐
已删除
Tensorflow2.0 混淆矩阵与打印准确率不符
【科普】无线电波怎样传送信息?
在华为云,见证迷你世界的神奇觉醒
MYSQL (Basic) - An article takes you into the wonderful world of MYSQL
Perfectly Clear QuickDesk & QuickServer图像校正优化工具
【每日一道LeetCode】——191. 位1的个数
牛客网——华为题库(100~108)
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
NXP IMX8QXP replacement DDR model operation process
Chapter 4 Controlling the Execution Flow
MindSpore:npu 多卡训练自定义数据集如何给不同npu传递不同数据
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
生物医学论文有何价值 论文中译英怎样翻译效果好
Spark学习:用spark实现ETL
AI Basics: Graphical Transformer
尊重客观事实
iPhone真是十三香?两代产品完全对比,或许上一代更值得买
【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest
VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误