android - BroadcastReceiver and PostDelay -
in activity have private broadcastreceiver
, when triggered, should update ui after ms. in activity have:
private broadcastreceiver broadcastreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { log.e("broadcastreciever: ", "updatecaselist"); update.refreshcaselist(); } };
this broadcastreceiver
beeing triggered service
:
@override public void oncreate() { super.oncreate(); intent = new intent(broadcast_action); } @override public void onstart(intent intent, int startid) { handler.removecallbacks(sendupdatestoui); handler.postdelayed(sendupdatestoui, 0); } private runnable sendupdatestoui = new runnable() { public void run() { handler.postdelayed(this, 10000); // 10 seconds sendupdatetouithread(); } }; private void sendupdatetouithread() { sendbroadcast(intent); }
i guess onstart
method being called when register broadcastreceiver in onresume()
method. unregister broadcastreceiver
in onpause
.
my intention should sent notification activity
, every 10 seconds. once start application, service notify activity every 10 seconds, planned. problem when leave activity , return back, doesn't post notification activity
every 10 seconds, @ random time. can see in logcat
randomness spamming occurs every 4, 6, 3, 8, 6 seconds , on. why on earth behaviour?
according postdelayed
documentation runnable called after millisecods elapsed and
time spent in deep sleep add additional delay execution.
so randomness design. expect runnable called after more 10000 ms in case.
Comments
Post a Comment