How to prevent Android displaying app stopped message -
android kill service when memory not enough.
like this:
i know can use foreground service prohibit android kill service
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 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); } }
but display notification on screen
i rather kill service display notification, don't want display stopped message.
i found app, can display no message when android kills it.
e.g. screen dimmer
how can prohibit android display app stopped message?
check this: https://stackoverflow.com/a/32229266/2965799
according have used following code handle exception. wanted display message added own message if use answer there no messages.
thread.setdefaultuncaughtexceptionhandler(new thread.uncaughtexceptionhandler() { @override public void uncaughtexception(thread paramthread, throwable paramthrowable) { new thread() { @override public void run() { looper.prepare(); toast.maketext(getactivity(),"your message", toast.length_long).show(); looper.loop(); } }.start(); try { thread.sleep(4000); // let toast display before app shutdown } catch (interruptedexception e) { } system.exit(2); } });
Comments
Post a Comment