1

Can anyone tell me how to call the n number of activities from different pages using sharedPreference?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Nakshatran
  • 426
  • 1
  • 7
  • 19

1 Answers1

2

You can save an array in your SharedPreference. Here's an example for that.

Your array can hold the names of your Activities. Like:

String activityNames[] = { "Activity1" , "Activity2" , "Activity3" };

Fetch this array from your SharedPreference, and then start the desired Activity using:

Class selected = Class.forName("learn.myandroidapp.hr." + activityNames[someIndex]);
Intent selectedIntent = new Intent(CurrentActivity.this,selected);
startActivity(selectedIntent);

I haven't given you the entire code, but the basic idea(which is more than sufficient,I believe). Feel free to enquire for more.

Community
  • 1
  • 1
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108