Okay, that confirms what I have been saying -- you set the value twice, once
when A was created, and once when B was created.  You finish B.  You haven't
changed the field.  It still points to B.  What else do you expect?

Btw, I will say again, doing this kind of thing is dangerous unless you have
a good understanding about activity lifecycles and all of the edge cases
that can happen; you are not dealing with a lot of things here (clearly just
the switch back from B to A).

Why are you even doing this at all?  Why not just create the MediaPlayer in
Application and play from there?  That would be a lot safer.  Better yet,
have a static function that you give the Application to; then you don't need
to have your own Application class at all.

On Mon, Apr 27, 2009 at 6:31 PM, Neo <mobi.liub...@gmail.com> wrote:

>
> Application class
> public class MyApplication extends Application{
>         public static MyApplication getApplication(Activity activity)
> {
>        // TODO should this be synchronized?
>        if (app == null)
>        {
>            initialize(activity);
>        }
>        mActivity = activity;
>        return app;
>    }
> }
>
> Activity A class:
> public class AActivity extends Activity{
>    public void onCreate(Bundle savedInstanceState){
>    app = MyApplication.getApplication(this);
>    }
> }
>
> Activity B class:
> public class BActivity extends Activity{
>    public void onCreate(Bundle savedInstanceState){
>    app = MyApplication.getApplication(this);
>    }
> }
>
> I set the activity point to the application, because i want create
> play sound function in the Application class.
>
> 1.when i onCreate() Activity A, i will set A point to the mActivity,
> and create B point to mActivity.
>
> 2.finish() B Activity, back to A onResume(),but i don't set the A
> point to mActivity.
>
> 3.Play sound, call the function in the Application,
>
>    public void playAudio() {
>       mMediaPlayer = MediaPlayer.create(mActivity, R.raw.type);
>       mMediaPlayer.start();
>    }
>
> the mActivity is B point, i know because i havn't reset point, but i
> finish the B activity, why i can play the sound used the B point
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to