android - Want to restart service if application stopped by user from application manager. -
i'm using sticky android service using code snippet in service class
@override public int onstartcommand(intent intent, int flags, int startid) { return start_sticky; }
but restarts when app force closed android o/s, although when user force stop app application manager, service terminated. however, requirement want keep running service forever till app installed in device. 1 me on this?
you can use forground service
make service alive.
@override public int onstartcommand(intent intent, int flags, int startid) { notification notification=new notification(r.drawable.icon,"the service running",system.currenttimemillis()); intent j=new intent(this, activity.class); pendingintent pi=pendingintent.getactivity(this, 0, j, 0); notification.setlatesteventinfo(this, "notification message", "runningservice", pi); notification.flags|=notification.flag_no_clear; startforeground(1, notification); return start_sticky; }
Comments
Post a Comment