当内存不足时,Android会杀死一些服务。如何防止Android显示应用程序停止消息
像这样:
我知道我可以使用前台服务,禁止机器人杀死我的服务
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
try {
Notification notification = new Notification(R.mipmap.ic_launcher,"this is service", System.currentTimeMillis());
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent , 0);
notification.setLatestEventInfo(this, "myapp", "myservice", contentIntent);
notification.flags =Notification.FLAG_AUTO_CANCEL;
startForeground(123,notification);
}
catch(Exception e)
{
stopSelf();
}
}
@Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
}
但是,这将在屏幕上
我显示通知宁愿杀服务比显示通知,但我也不想显示停止的消息。
我发现了一些应用程序,当android杀死它时,它不会显示任何消息。
例如Screen Dimmer
如何禁止android显示应用程序停止的消息?