java - Using Intent Service in combination with Alarm Manager -
i have used alarm manager allow user schedule task repeat @ amount of time. in context of application, have android game people able schedule when send ships. alarm manager working fine, alarms kicked off @ right time etc.
what happens when alarm fired off (usually every hour , bit), intentservice start communicating server send ships. action may take 1 minute, can last 10 minutes. works fine. alarms fired, ships sent, happy. problem arises @ night, go sleep , expect when waking ships have been sent night long. nope. logging & notifications show alarms fired correctly, appears intentservice killed when it's communicating server.
possible cause i'm not looking @ game every once in while when i'm awake, , keep form of process running prevents intentservice being garbage collected.
i've tried lot of things fix this. used work broadcastreceiver, used spawn asynctasks in intentservice, i've since refactored code not use things anymore they're bad practice services.
i have checked resource: http://techtej.blogspot.com.es/2011/03/android-thread-constructspart-4.html i'm still not sure if i'm doing correct thing handle situation. have placed extensive logging next night review in morning i'd guys' opinion on this.
oh i'm requesting wakelock complete duration of onhandleintent function using:
powermanager pm = (powermanager) c.getsystemservice(context.power_service); this.wakelock = pm.newwakelock(powermanager.partial_wake_lock | powermanager.on_after_release, "myapplicationwakelock"); my intentservice:
public class scheduledrequestservice extends intentservice { public scheduledrequestservice() { super("scheduledrequestservice"); } @override public int onstartcommand(intent intent, int flags, int startid){ logger.d("onstartcommand!"); return super.onstartcommand(intent, flags, startid); } @override protected void onhandleintent(intent intent) { scheduledrequest request = (scheduledrequest) intent.getextras().getserializable("request"); // function start lot of client <-> server communication request.onexecute(this, intent); } @override public void ondestroy(){ logger.d("ondestroy!"); super.ondestroy(); } } so again, question is; structuring correctly? should use normal service instead of intentservice ? can intentservice garbage collected while handling intent (i think read possible)?
can intentservice garbage collected while handling intent (i think read possible)?
no, process can terminated.
am structuring correctly?
not if trying use _wakeup alarm. need set things more in case, , recommend either wakefulbroadcastreceiver or my wakefulintentservice handle pattern.
should use normal service instead of intentservice ?
no, intentservice fine. may need consider making foreground service using startforeground().
Comments
Post a Comment