当前位置:网站首页>跨进程启动后台服务
跨进程启动后台服务
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);
}
}边栏推荐
- WEBSOCKETPP使用简介+demo
- The use of @ symbol in MySql
- - daily a LeetCode 】 【 191. A number of 1
- Recommendation | People who are kind to you, don't repay them by inviting them to eat
- 尊重客观事实
- natural language processing nltk
- C# wpf 无边框窗口添加阴影效果
- 中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
- 荐号 | 对你有恩的人,不要请吃饭来报答
- WeChat Mini Program Cloud Development | Urban Information Management
猜你喜欢

kotlin by lazy
![[Prometheus] An optimization record of the Prometheus federation [continued]](/img/5d/56e171b7a02584337a0cfe5c731fb2.png)
[Prometheus] An optimization record of the Prometheus federation [continued]

基于inquirer封装一个控制台文件选择器

开心的聚餐

Recommended Books | Recommend 3 database books with rave reviews

Pytorch foundation -- tensorboard use (1)

Fixed asset visualization intelligent management system

Read the "Language Model" in one article

node封装一个控制台进度条插件

Redis for infrastructure
随机推荐
The sixteenth issue of eight-part article Balabala said (MQ)
LocalDate时间生成
MongoDB打破了原则引入SQL?
Hello, my new name is "Bronze Lock/Tongsuo"
开心的聚餐
不同的路径依赖
防抖和节流有什么区别,分别用于什么场景?
2种手绘风格效果比较,你更喜欢哪一种呢?
Two-point answer naked question (plus a little pigeonhole principle)
VBA 连接Access数据库和Excle
JS提升:Promise中reject与then之间的关系
Recommendation | People who are kind to you, don't repay them by inviting them to eat
while,do while,for循环语句
kotlin的by lazy
3D机器视觉厂商的场景争夺战役
载誉而归,重磅发布!润和软件亮相2022开放原子全球开源峰会
Codeblocks + Widgets create window code analysis
core sound driver详解
Spark学习:用spark实现ETL
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用