android - Runnable stopped when activity is paused -
i have clock done updating textview text using runnable. when i'm in activity textview updated properly, when leave , come activity, code in run()
method not executed anymore.
do have call run()
again in onresume
of activity? why? mticker runnable stopped?
myactivity.java
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mhandler = new handler(); mticker = new runnable() { public void run() { if(mclockstopped) return; long = system.currenttimemillis(); mcalendar.settimeinmillis(now); mclock.settext(dateformat.format("kk:mm", mcalendar)); mclock.invalidate(); long uptime = systemclock.uptimemillis(); long next = uptime + (60000 - % 60000); mhandler.postattime(mticker, next); } }; mticker.run(); /* more stuff */ } @override public void onresume() { super.onresume(); mclockstopped = false; } @override public void onpause() { mclockstopped = true; super.onpause(); }
maybe not simple, setting mclockstopped true make runnable's run() exit.
you should call
mclockstopped = false; mticker.run();
in onresume
Comments
Post a Comment