【转】android让普通app不被其他程序kill
16lz
2021-01-23
转自: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"就好
更多相关文章
- 【Flutter】修改图标、应用名称、包名等
- Android 4.0 对通知栏图标的尺寸有要求
- Android开发—利用FrameLayout实现图标中间显示文字
- Android SDK and AVD Manage图标没找到
- android每隔5s显示时间
- 关机充电图标
- Android中实现日期时间选择器(DatePicker和TimePicker)