2

I have an application with a MainActivity and few other activites. From the MainActivity I start a preference screen, where I set theme for my application.

MainActivity-> Settings->Choose Theme

Currently how it works:

I restart the application, start my Main activity and theme is applied to all the activites.

How I want it to work:

I want to restart the application and go back to the same screen where I set my Theme and not my MainActivity.

Can anyone please suggest me some ways in which I can do it?

Thank you in advance

EDIT:

How I want it to work:

Restart the application -> Go back to the "Choose Theme" Screen (Where it is set) .

Then when I press back button -> Settings screen -> and when pressed back again to my MainActivity.

quad
  • 872
  • 3
  • 17
  • 37

1 Answers1

0

I don't know if this is the best way, but you can save in SharedPreferences the Last screen you were on (or if it's just for this case, a boolean to know if you're coming from a restart) and each time when the application start on onCreate() of MainActivity check the key in SharedPreferences and go to your Themes activity accordingly

Dany Y
  • 6,833
  • 6
  • 46
  • 83
  • Thank you for your response..But I have many options in my Settings screen ( upto 8 options) and one of them is to select the theme. So basically a two level tree. – quad Sep 13 '12 at 08:21
  • Yes the sharedpreferences key s independant of all the options, its just one more key to tell you which activity to launch at first.Or i didn't understand you correctly ? – Dany Y Sep 13 '12 at 08:24
  • No..I think I will try this and will let you know if it works. – quad Sep 13 '12 at 08:29
  • Ok I tried it.But some problems. The "choose theme" screen is not an activity but a preference provider class. So I tried to open my "Settings" screen and it worked, but when I press back button the application closes and does not go back to my MainActivity. Maybe I didnt put it properly in my question. I will edit it. – quad Sep 13 '12 at 08:53
  • I think you need to override `onBackPressed()`. check if the settings screen is open, if yes close it, if not call `super.onBackPressed()` – Dany Y Sep 13 '12 at 10:01