Click here to Skip to main content
15,886,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am making an application which plays some music. I used the Media player class and got it working. I also added extra function via menu button pressed.
1st problem:
I start the music... I have another screen to which i jump with the help of an intent (when menu item pressed). The problem is when I jump back with an intent to mymedia player, i can start the music all over again, it doesn't return to the state in which it was when I jumped to another activity resulting in 2 music files simultaneously playing.
How can I return to the state I left the application when I pressed the menu button?

2nd problem:
I want my media player playing in the background when I press the back button, and when I start the application again, to be in the same state I left it when I pressed the back button.

Thanks for your help in advance!
Posted

You have to save the state of your buttons.

Set up a facade for this ( Facade Pattern @ wikipedia[^] ) and store the state of all buttons, menues, and what else needs to be remembered in there (also see the article from Nagy "The Secret Classes or How I Stopped Counting and Loved the Enumerator"[^]).

The facade has to be set up when the app starts and should be disposed when the app exits.

regards
Torsten
 
Share this answer
 
v2
Comments
Nagy Vilmos 10-Jun-11 12:06pm    
I'll 5 you just for the reference!
I am guessing here, but check that you are not inadvertently creating a new instance of the media player when you call back to it.
 
Share this answer
 
Comments
Alfie Torok 10-Jun-11 7:26am    
It only loads the media player when onCreate() is called, and that is called every time the activity starts...how can I go around this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900