How the Activities are kept in preference screen s

2019-09-11 05:02发布

How can activities be saved in listView preferences so that when a User selects an activity in preferences so that when user starts the app next time they will appear as a first screen?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-09-11 05:37

When user choose an Activity to save on it's preferences,You can save name of that Activity to sharedPreferences. Then in your MainActivity class when app runs again, check for saved activity and start that.

see this SO question

To save to preferences:

PreferenceManager.getDefaultSharedPreferences(context).edit().putString("MYACTIVITY", "myStringToSave").commit();

To get a stored preference:

PreferenceManager.getDefaultSharedPreferences(context).getString("MYACTIVITY", "defaultStringIfNothingFound"); 

where myStringToSave could be name of chosen activity

查看更多
登录 后发表回答