当前位置:网站首页>跨进程启动后台服务
跨进程启动后台服务
2022-07-30 18:58:00 【菜鸟xiaowang】
public class MyService extends Service {
private static final String CHANNEL_ID = "100";
private static final String CHANNEL_NAME = "APK1";
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public 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);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setAction("android.intent.action.START_SERVICE");
第一个参数是包名 第二个参数是包名加类名
intent.setComponent(new ComponentName("com.example.apk2","com.example.apk2.MyService"));
intent.putExtra("msg","跨进程启动service");
startForegroundService(intent);
Log.e(getClass().getName(), "startService end");
}
},30 * 1000);
return super.onStartCommand(intent, flags, startId);
}
}
边栏推荐
- Scala学习:breakable
- 还有三天忙完
- 6块钱1斤,日本公司为何来中国收烟头?
- Does the satellite phone communicate directly with the satellite or through a ground station?
- Vulkan开启特征(feature)的正确姿势
- Pytorch foundation -- tensorboard use (1)
- node封装一个控制台进度条插件
- 3D机器视觉厂商的场景争夺战役
- nlohmann json 使用指南【visual studio 2022】
- What kind of framework is friendly to developers?
猜你喜欢
随机推荐
自己需要努力
Hello, my new name is "Bronze Lock/Tongsuo"
MYSQL (Basic) - An article takes you into the wonderful world of MYSQL
Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!
Recommendation | People who are kind to you, don't repay them by inviting them to eat
6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?
VBA批量将Excel数据导入Access数据库
[Summary] 1396- 60+ VSCode plugins to create a useful editor
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
还有三天忙完
WEBSOCKETPP使用简介+demo
JS提升:Promise中reject与then之间的关系
The use of terminal split screen tool Terminalx
OSPF详解(4)
OneFlow source code analysis: Op, Kernel and interpreter
(2022杭电多校四)1001-Link with Bracket Sequence II(区间动态规划)
A senior with 13 years of experience in software testing, summed up 5 test employment suggestions....
node封装一个控制台进度条插件
- daily a LeetCode 】 【 191. A number of 1
常见链表题及其 Go 实现