Hi
I have an application that starts a background thread to load data. It
uses Handler to pass data back to the main thread. Now this works
perfectly most of the time, but not when I switch orientation.
What I found was this behavior:
- onCreate : Start main view, with background load thread
- Switch android direction
- onStop : Kill background loading thread, does thread.interrupt +
thread.join.
- onCreate
- Data queue'd in the handler is still being pushed through from the
previous data load.
This produces a bit of a race condition for me. I can shutdown the
thread cleanly, but the data that's in the handler, between the thread
and the main view isn't always cleared.
This would be solvable with something like:
thread.interrupt();
thread.join();
handler.clear();
Before returning to the onStop function, but there's no .clear to just
empty a handler out.
How can I clear a Handler of all messages? I use this for posting:
handler.post(new Runnable() {
@Override
public void run() {
handler.onData(sendData);
}
});
So doing a .removecallback (which requires me to store runnables)
isn't real practical.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en