0

I have a problem with resume Activity. I have a MainActivity which contains other activities. Each one contains a radio station. I have a button (Play) in each activity, and when the user clicks on it, the button changes its function to Stop, so it turns to Stop button. My problem is that when I go for example from Activity(B) to MainActivity and then return to Activity(B) instead of the Stop button, it shows again the Play button, and if the button is pressed, the player plays the same station again at the same moment. I tried to resume the activity using flag, but that didn't work.

My code looks like this:

if (position == 3) {
    Intent intent = new Intent(RadioActivity.this, Taraf.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);  
}

And the manifest looks like this:

<activity
    android:name=".SettingsActivity"
    android:launchMode="singleTop"
    android:screenOrientation="portrait">
</activity>

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:launchMode="singleTop">
</activity>
Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
DenisHD
  • 19
  • 6
  • Have a look at this http://stackoverflow.com/questions/7687447/how-to-resume-activity-from-previous-state-after-handling-incoming-call-in-andro – Rajan Kali Sep 19 '15 at 10:32

2 Answers2

0

You should save the status of your button in sharedPreferences, and retrive it when you return to Activity(B), then reset your button according to status of the button saved in sharedpreferences.You can refer to this documentation.

Darshan
  • 515
  • 1
  • 3
  • 16
0

you have to save the state somewhere whether in shared preferences or any other storage. An d when you are returning to your activity you can retrieve this data.

RajSharma
  • 1,941
  • 3
  • 21
  • 34