AsyncTask doesn't know anything about activities or their lifecycles.
If you leave your activity with the back key, it's actually destroyed. So when you come back (by launching again, or by using the recent apps list [long-pressing the home key]), it will be created all over again.
It's up to your code to handle activity lifecycle callbacks, and do what's meaningful in this situation for your application (like canceling an AsyncTask).
-- Kostya 14.02.2011 22:15, DanielleM пишет:
Hello all: I'm trying to use an AsyncTask to prepare two MediaPlayer objects while the rest of my activity loads. However, I've noticed that once everything is loaded...I'm able to play my media player just fine, but if I switch to another activity in my app and then switch back to the media player activity the Media Player objects get re-created and so the code I have in the onClick listeners for the buttons no longer works. Basically, the app loads, the streams are set up..once this is done you can press play to play one of the streams and then stop to pause it. But if I switch to another activity while the streams are playing and then go back to the MediaPlayer activity, I can no longer stop the streams. Does an AsyncTask run every time the activity is brought back to the front? That doesn't seem right since the code is in the onCreate method and the activity should not be re-created every time it's brought back to the front. If anyone can shed some light on what's happening here I'd really appreciate it. The buttons and streams were functioning properly before I started pushing the setup code to an AsyncTask...I just figured it was too taxing on the system to do the set up in the main thread. So I decided to push that to a background thread while the rest of the activity loads. Thanks, DanielleM
-- Kostya Vasilyev -- http://kmansoft.wordpress.com -- 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

