这是我在 StackOverflow 上的第一篇文章。
基本上,我的应用程序首先检查我的 Sqlite 数据库中是否存在用户记录。如果是,我希望它显示我的主应用程序屏幕。如果没有,我希望显示另一个屏幕,提示用户输入密码。
此密码屏幕是我的应用程序的新增内容。它最初只是显示主屏幕,如下所示:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
然后我将为用户运行检查。如果找不到用户,我会像这样显示密码屏幕:
Intent myIntent = new Intent(this, loginScreenActivity.class);
startActivityForResult(myIntent, 0);
问题是,如果我决定点击“后退”按钮从密码屏幕退出应用程序,它会返回到主屏幕。
我如何首先运行检查,然后显示两个视图之一?
希望这是有道理的。
提前致谢。
This is my very first post on StackOverflow.
Basically, my app starts by checking to see if a user record exists in my Sqlite Database. If yes, I would like it to display my main application screen. If not, I would like another screen to be displayed, prompting the user for a password.
This password screen is a new addition to my app. It originally just displayed the main screen like so:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Then I would run the check for a user. If no user is found I display the password screen like so:
Intent myIntent = new Intent(this, loginScreenActivity.class);
startActivityForResult(myIntent, 0);
The problem is, if I decide to hit the BACK button to exit out of the application from the password screen, it goes back to the main screen.
How can I first run the check, then display one of the two views??
Hope this makes sense.
Thanks in advance.
发布评论
评论(2)
当您导航到登录屏幕时,在第一个屏幕上调用 finish()
When you navigate to the login screen, call finish() on the first screen
阅读 Activity 文档,这会非常有用有帮助。
如果您不想返回此屏幕,则需要设置 FLAG_ACTIVITY_CLEAR_TOP。
或者第二个,重写 onbackpressed() 方法并在其中使用 finish() 方法。
read the Activity documentation, it will be very helpful.
You need to set the FLAG_ACTIVITY_CLEAR_TOP if you never wan1t go back to this screen.
Or the secont one, override the onbackpressed() method and use finish() method inside in.