android - How to stop the handler? -
i have doubt .. having hander in activity in application. though activity destroyed handler still functioning. running on different process other application process ? 1 plz explain why working ? possible stop handler while ondestroy of activity ?
thanks in advance.
as described in documentation
http://developer.android.com/reference/android/os/handler.html
"each handler instance associated single thread , thread's message queue."
when finish activity, e.g. in ondestroy()
need cancel callback runnable started for:
mhandler.removecallbacks(previouslystartedrunnable);
you can without checking if runnable fired while activity active.
update:
there 2 additional cases considered:
1.) have implemented handler in way created new class runnable, e.g.
private class handleupdateind implements runnable...
usually need if have start delayed runnable current set of parameters (which may change until runnable fires). cancel need use
mhandler.removecallbacksandmessages(handleupdateind.class);
2.) if using inline call (jpm comment)
handler = new handler() { public void handlemessage(message msg) { ... } };
then need define "what" value message. later on, if need cancel can use
handler.removemessages(what);
to perform task.
Comments
Post a Comment