当前位置:网站首页>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);}}边栏推荐
- 电脑死机的时候,发生了什么?
- MindSpore:【JupyterLab】查看数据时报错
- OneFlow源码解析:Op、Kernel与解释器
- requet.getHeader("token") is null
- VS Code 连接SQL Server
- What is the value of biomedical papers? How to translate the papers into Chinese and English?
- DM8: Single database and single instance to build a local data guard service
- - daily a LeetCode 】 【 191. A number of 1
- Golang logging library zerolog use record
- Scrapy framework is introduced
猜你喜欢
随机推荐
LocalDate时间生成
[Prometheus] An optimization record of the Prometheus federation [continued]
牛客刷题系列之进阶版(搜索旋转排序数组,链表内指定区间反转)
几个GTest、GMock的例子
The use of terminal split screen tool Terminalx
MindSpore:【JupyterLab】查看数据时报错
第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
阿里云武林头条活动分享
Node encapsulates a console progress bar plugin
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
Entering the applet for the first time
Another company interview
requet.getHeader("token") is null
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
谷歌AlphaFold近日宣称预测出地球上几乎所有蛋白质结构
Witness the magical awakening of the mini world in HUAWEI CLOUD
The use of @ symbol in MySql






![[TypeScript]编译配置](/img/ac/64ebd33de977e35620dbc18d2adfad.png)


