0

I am developing an application in Android Studio and want to make a favourites page. To do this, I would like the user to be able to save the activity to the favourites, and when opening the favourites page from the home page, the user can view the button to start this activity.

I have looked up numerous other similar questions but none which suits my specific issue.

I have looked at different possibilities such as SharedPreferences, ToggleButton etc. but none I can get to work.

I would really appreciate your help.

Thank you so much in advance.

User10
  • 27
  • 5
  • Store the classname in sharedpreferences, it's a string so is easy. `Activity.class.getName()` later you can use that name reference the class and start the activity – Tim May 20 '16 at 10:33
  • Sounds great, but I am really not familiar with SharedPreferences as I have never used it until trying it with this which didn't work out so well, are you able to assist in what way the code should be written for this please? – User10 May 20 '16 at 10:34
  • 1
    Better get familiar with it then. Just Google how to use it. It's quite easy – Tim May 20 '16 at 10:36
  • It's literally **the** thing you're going to have to become familiar with since it's very often used. – Vucko May 20 '16 at 10:43

1 Answers1

0

May be you can create a static object of HashMap and save favorite activities to this and can retrieve activities from that. Something like this.

This HashMap Object can be kept in Application Class so you can access user list of fav activities anywhere from the App.

private static final Map<String, Class> favActionMap;
   favActionMap= new HashMap<>();
        favActionMap.put("FAV_1", AddFixtureActivity.class);
        favActionMap.put("FAV_2", AddSwitchActivity.class);
        favActionMap.put("FAV_3", CommissionStatusActivity.class);

To store the data persistently ,save it in database or shared preferences

Nargis
  • 4,687
  • 1
  • 28
  • 45
  • This data will be lost when you close the app – Tim May 20 '16 at 10:37
  • Not sure what is meant by: favActionMap.put("FAV_1", AddFixtureActivity.class); favActionMap.put("FAV_2", AddSwitchActivity.class); favActionMap.put("FAV_3", CommissionStatusActivity.class); And not sure how to implement this function i.e. do I just put this code in the main activity and then have a favourites but in each activity which relates back to this hashmap? – User10 May 20 '16 at 10:38
  • I have just given you an example, you can put any String like "FAV_1" and match it to a favorite activity. You will put this data in HashMap when user marks one of the activities as a fav activity – Nargis May 20 '16 at 10:42