【转】android让普通app不被其他程序kill
16lz
2021-12-04
转自:google搜索 android startForeground
如http://blog.csdn.net/yyingwei/article/details/8509402
运行一个service
PS:system应用的话,直接在AndroidManifest中的application标签加入android:persistent="true"就好
如http://blog.csdn.net/yyingwei/article/details/8509402
运行一个service
@Override public void onDestroy() { // Make sure our notification is gone. stopForegroundCompat(R.string.system_message_title); super.onDestroy(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Builder builder = new Notification.Builder(this); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DeskSetting.class), 0); builder.setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_launcher)// 设置状态栏里面的图标(小图标) // .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表里面的图标(大图标) // .setTicker("this is bitch!") //设置状态栏的显示的信息 .setOngoing(false) .setOnlyAlertOnce(true) .setShowWhen(false) .setOnlyAlertOnce(true) .setPriority(Notification.PRIORITY_MIN) .setWhen(System.currentTimeMillis())// 设置时间发生时间 .setAutoCancel(true)// 设置可以清除 .setContentTitle(getText(R.string.fetion_launcher_started))// 设置下拉列表里的标题 .setContentText(getText(R.string.about_desk));// 设置上下文内容 Notification notification = builder.getNotification(); notification.flags = Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; Log.d(TAG, "notification.flags " + notification.flags); startForeground(3030, notification);// startForegroundCompat(1166, notification); mNM.cancel(3030); return super.onStartCommand(intent, flags, startId); }
PS:system应用的话,直接在AndroidManifest中的application标签加入android:persistent="true"就好
更多相关文章
- Android(安卓)学习笔记6 —— Activity 布局学习1
- android之知识点小结二
- Android横竖屏切换不重新调用onCreate()
- Android(安卓)O添加Settings设置项的方法
- Android中View图形绘制基础
- Android(安卓)UI 之TextView控件属性列表
- Android中app的请求抓包工具 Fiddler 详解
- Android(安卓)React Native自定义组件的流程
- 关于Android横竖屏的设置和使用