当前位置:网站首页>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);}}
边栏推荐
猜你喜欢
【MindSpore1.2.0-rc1产品】num_workers问题
JS提升:Promise中reject与then之间的关系
MindSpore:【Resolve node failed】解析节点失败的问题
第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结
【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
MindSpore:【MindSpore1.1】Mindspore安装后验证出现cudaSetDevice failed错误
卫星电话是直接与卫星通信还是通过地面站?
Recommendation | People who are kind to you, don't repay them by inviting them to eat
Node encapsulates a console progress bar plugin
VBA 连接Access数据库和Excle
随机推荐
Anaconda Navigator stuck on loading applications
SimpleOSS third-party library libcurl and engine libcurl error solution
ResNet18-实现图像分类
Encapsulates a console file selector based on inquirer
The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
MindSpore:ImageFolderDataset数据读取问题
DM8:单库单实例搭建本地数据守护服务
浅聊对比学习(Contrastive Learning)第一弹
VS Code connects to SQL Server
Does the satellite phone communicate directly with the satellite or through a ground station?
【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
阿里云武林头条活动分享
Alibaba Cloud Martial Arts Headline Event Sharing
How do radio waves transmit information?
什么是 RESTful API?
监听开机广播
MindSpore:【JupyterLab】按照新手教程训练时报错
VBA batch import Excel data into Access database
【科普】无线电波怎样传送信息?