Question

I have an activity that displays a loading screen while a worker thread is loading my game. While loading the worker thread updates a textview on the activity to display its current status. When finished it will close the loading activity and start the actual game activity. The worker thread is created in the onCreate() method and is given a newly created handler.

However what happens when the activity is destroyed and restarted e.g. by orientation change? IMHO the onCreate() methods would create a new worker thread while the first one is still loading, so now I got multiple worker threads doing the same.

What is the best way to prevent this and inform the worker thread about the new activity (so it can post its status updates).

Was it helpful?

Solution

Have you tied the DroidFu library? It has a class named BetterAsyncTask that seems to be targeted at getting rid of the problem you're talking about. You can find the library here ( https://github.com/kaeppler/droid-fu ) and an article about your problem and droidfu here ( http://brainflush.wordpress.com/2009/11/16/introducing-droid-fu-for-android-betteractivity-betterservice-and-betterasynctask/ - see the "That Dratted AsyncTask" section).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top