如何在应用程序启动时显示Android偏好设置屏幕?
问题描述:
我对Android开发非常陌生。
我希望我的Android应用程序在第一次运行时启动首选项页面。
关于如何做到这一点的任何提示?
谢谢。如何在应用程序启动时显示Android偏好设置屏幕?
答
您需要使用sharedpreference来保存布尔首选项。
这应该适合你。
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean previouslyStarted = prefs.getBoolean("PREVIOUSLY_STARTED, false);
if(!previouslyStarted){
SharedPreferences.Editor edit = prefs.edit();
edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE);
edit.commit();
showPreference();//Here you launch your Preference Activity if it hasnt been launched before.
}
答
存储“has_launched_before”之类的隐藏偏好设置。在启动时,检查该首选项,如果它是假的,则显示首选项屏幕而不是主屏幕,并将该首选项设置为true,以便在后续启动时不会发生。
+0
谢谢,我试图打开onStarting()中的首选项页面,但它崩溃了我的应用程序。任何想法为什么? –
什么 “首选项页” 你指的是?这是您的应用的首选项对话框,还是针对网络连接和其他电话/设备设置等特定的电话首选项对话框? – plainjimbo
像这个?: http://*.com/questions/3612978/show-version-info-only-once-on-application-start-in-android-app 或?: http://*.com/questions/3608483/what-is-sharedpreferences-in-android/3608517#3608517 – cschooley
像这样: http://*.com/questions/3612978/show-version-info-仅在应用程序中启动一次在Android应用程序 或: http://*.com/questions/3608483/what-is-sharedpreferences-in-android/3608517#3608517 – cschooley