当前位置:网站首页>跨进程启动后台服务
跨进程启动后台服务
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);
}
}
边栏推荐
- 运营 23 年,昔日“国内第一大电商网站”黄了...
- 【PHPWord】PHPOffice 套件之PHPWord快速入门
- MySQL数据类型
- [TypeScript]编译配置
- Recommendation | People who are kind to you, don't repay them by inviting them to eat
- MongoDB打破了原则引入SQL?
- 3D机器视觉厂商的场景争夺战役
- 固定资产可视化智能管理系统
- OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
- AWS 控制台
猜你喜欢
OSPF详解(4)
C# wpf 无边框窗口添加阴影效果
【每日一道LeetCode】——191. 位1的个数
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
What is the value of biomedical papers? How to translate the papers into Chinese and English?
智慧中控屏
延时队列优化 (2)
VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
随机推荐
还有三天忙完
requet.getHeader(“token“) 为null
LeetCode 练习——关于查找数组元素之和的两道题
攻防世界web-Cat
vxe-table实现复选框鼠标拖动选中
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
AI基础:图解Transformer
Range.CopyFromRecordset 方法 (Excel)
Multiple instances of mysql
《痞子衡嵌入式半月刊》 第 59 期
The use of @ symbol in MySql
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
Spark学习:编译Spark项目时遇到的报错
你好,我的新名字叫“铜锁/Tongsuo”
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
natural language processing nltk
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!
【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
[TypeScript]编译配置