No, you tell it to cancel when your activity is *paused* (probably
combined with a check for isFinishing()).
And actually, you don't need to use an AsyncTask for a media player:
http://developer.android.com/reference/android/media/MediaPlayer.html#prepareAsync()
public void prepareAsync ()
Since: API Level 1
*Prepares the player for playback, asynchronously*. After setting the
datasource and the display surface, you need to either call prepare()
or prepareAsync(). *For streams, you should call prepareAsync(), which
returns immediately*, rather than blocking until enough data has been
buffered.
To cancel prepareAsync, I *think* you just call release(), but honestly,
I haven't used MediaPlayer too much.
-- Kostya
14.02.2011 22:33, Danielle Murkerson пишет:
Ok that's good to know...I didn't see anything about that in the
docs...So I could just tell it to cancel when the activity resumes.
Thanks,
DanielleM
On Mon, Feb 14, 2011 at 2:32 PM, Kostya Vasilyev <[email protected]
<mailto:[email protected]>> wrote:
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]
<mailto:[email protected]>
To unsubscribe from this group, send email to
[email protected]
<mailto:android-developers%[email protected]>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
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
--
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