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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---