How the Activities are kept in preference screen settings

自古美人都是妖i 提交于 2019-12-12 05:23:41

问题


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:


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



来源:https://stackoverflow.com/questions/38804071/how-the-activities-are-kept-in-preference-screen-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!