当前位置:网站首页>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);}}边栏推荐
- C# wpf 无边框窗口添加阴影效果
- 中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
- 【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
- The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
- Common linked list problems and their Go implementation
- 【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest
- VS Code 连接SQL Server
- 第4章 控制执行流程
- node封装一个控制台进度条插件
- MYSQL (Basic) - An article takes you into the wonderful world of MYSQL
猜你喜欢

NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...

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

VBA批量将Excel数据导入Access数据库

【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。

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

C# wpf 无边框窗口添加阴影效果

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

VS Code connects to SQL Server

SimpleOSS third-party library libcurl and engine libcurl error solution
![[TypeScript]编译配置](/img/ac/64ebd33de977e35620dbc18d2adfad.png)
[TypeScript]编译配置
随机推荐
什么是 RESTful API?
055 c# print
requet.getHeader(“token“) 为null
【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
What is the difference between a cloud database and an on-premises database?
Listen to the boot broadcast
架构师如何成长
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
Alibaba Cloud Martial Arts Headline Event Sharing
【刷题篇】计算质数
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
Spark学习:用spark实现ETL
Win11如何更改默认下载路径?Win11更改默认下载路径的方法
The use of terminal split screen tool Terminalx
How do radio waves transmit information?
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
【剑指 Offe】剑指 Offer 18. 删除链表的节点
Vulkan开启特征(feature)的正确姿势