Android 应用程序中的一次性设置注册屏幕?
嗨,我想在我的应用程序中实现,用户必须注册一次,当他再次打开应用程序时,他应该直接去欢迎活动,而不去注册活动。那么如何实现这一点呢Android 应用程序中的一次性设置注册屏幕?,android,android-intent,android-fragments,Android,Android Intent,Android Fragments,嗨,我想在我的应用程序中实现,用户必须注册一次,当他再次打开应用程序时,他应该直接去欢迎活动,而不去注册活动。那么如何实现这一点呢 savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if(savedPreferences.getBoolean(PREF_SHOW_ABOUT_ON_APP_START, true)){ Intent intent = new Intent(this
savedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if(savedPreferences.getBoolean(PREF_SHOW_ABOUT_ON_APP_START, true)){
Intent intent = new Intent(this, SetupActivity.class);
startActivity(intent);
savedPreferences.edit().putBoolean(PREF_SHOW_ABOUT_ON_APP_START, false).commit(); // YOu could do this line within the SetupActivity to ensure they have actually done what you wanted
finish();
} else {
// Go somewere else
}
我试过这个
谢谢创建两个活动XML文件。一个用于注册,另一个用于应用程序。但是你应该只有一个活动课。在类onCreate()函数中,检查用户是否已重新注册。如果已注册,则显示主应用程序XML文件;如果未显示注册XML,则显示主应用程序XML文件 编辑:
SharedPreferences preference = getSharedPreferences("PREFERENCE", MODE_PRIVATE);
boolean status = preference.getBoolean("registration_completed", false);
if (status){
setContentView(R.layout.registration_form);
}else{
setContentView(R.layout.main_app);
}
以下是步骤:
- 在设置/注册屏幕中,单击注册按钮并完成作业后,使用恒定键将操作结果保存在共享首选项中
- 创建一个splash活动,使其成为您的初始活动
- 在splash活动的onResume方法中,检查相关键的值。
- 如果已注册,则启动主要活动
- 否则显示设置/注册活动
setContentView()
不是setDialogLayoutResource()我已经更正了我对setContentView的回答,但无论是第一次还是下次,他转到else语句时,请告诉我如何解决,这意味着没有保存首选项。在这里,我发布代码只是为了阅读偏好。我还以为你知道偏好的一切。转到这个链接。在这里,我为一个编辑和保存/阅读偏好的家伙发布了一个答案