android - how to run app in background on devices that kill background services (like Xiomi)? -


i have tried running service in background. have used start_sticky. answer. works in many devices fine in devices xiaomi lenovo service dies when app removed "recent app" screen. have tried deactivating power saver particular apps , full system doesn't work either.

how make work in devices? know possible because apps (like whatsapp) , games able send notification when app not in "recent app" screen.

you can create alarm 1min in ontaskremoved() method in service class. automatically invoke after 1min , restarts service.

in service class

public void ontaskremoved(intent rootintent) {      intent restartservice = new intent(getapplicationcontext(), yourservice.class);      restartservice.setpackage(yourpackagename);      pendingintent restartserviceintent = pendingintent.getservice(getapplicationcontext(), 1, restartservice, pendingintent.flag_one_shot);      alarmmanager alarmservice = (alarmmanager) getapplicationcontext().getsystemservice(context.alarm_service);      alarmservice.set(alarmmanager.elapsed_realtime, systemclock.elapsedrealtime()+1000, restartserviceintent); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -