service - android handler thread takes more time when screen is off -
i wrote simple app has activity , service(run in foreground). service need periodical job,so create handler, , send handler message periodically.
class servicehandler extends handler { public servicehandler(looper looper) { super(); } @override public void handlemessage(message msg) { switch (msg.what) { case 1: // job here this.sendemptymessagedelayed(1, 15000); } } }
i think job should execute every 15s, , never ends long service not killed user.
but when exit activity (long press menu key, sweep out activity) , turn screen off. job seems executed @ random interval(all longer 15s) , longer 1 minute.
i think relative android system power policy.
how can make job execute @ fix interval in such circumstance. pleas help.
when remove activity recent activity list, process finishes android framework. so, servicehandler
should stop processing.
as practise, developer should add code stop
such service processing in ondestroy()
Comments
Post a Comment