当前位置:网站首页>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);}}
边栏推荐
- LeetCode每日一题(1717. Maximum Score From Removing Substrings)
- C# wpf 无边框窗口添加阴影效果
- The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
- Google's AlphaFold claims to have predicted almost every protein structure on Earth
- Vulkan开启特征(feature)的正确姿势
- VBA 连接Access数据库和Excle
- MindSpore:【JupyterLab】按照新手教程训练时报错
- 几个GTest、GMock的例子
- Perfectly Clear QuickDesk & QuickServer图像校正优化工具
- MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
猜你喜欢
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
VBA runtime error '-2147217900 (80040e14): Automation error
【MindSpore】多卡训练保存权重问题
阿里云武林头条活动分享
C# wpf 无边框窗口添加阴影效果
[Prometheus] An optimization record of the Prometheus federation [continued]
Node encapsulates a console progress bar plugin
基于inquirer封装一个控制台文件选择器
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
Recommendation | People who are kind to you, don't repay them by inviting them to eat
随机推荐
VS Code 连接SQL Server
Difference between Object and Map
MySql中@符号的使用
跨进程启动后台服务
requet.getHeader("token") is null
【MindSpore】多卡训练保存权重问题
跨域问题的解决方法
- daily a LeetCode 】 【 191. A number of 1
VBA runtime error '-2147217900 (80040e14): Automation error
VBA批量将Excel数据导入Access数据库
【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
golang日志库zerolog使用记录
6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?
【科普】无线电波怎样传送信息?
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!
Tensorflow2.0 混淆矩阵与打印准确率不符
Chapter 14 Type Information
NXP IMX8QXP replacement DDR model operation process
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
Scrapy框架介绍