如何根据条件使用两个视图之一打开我的 Android 应用程序?

发布于 2024-12-13 15:13:03 字数 557 浏览 2 评论 0 原文

这是我在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筱果果 2024-12-20 15:13:03

当您导航到登录屏幕时,在第一个屏幕上调用 finish()

When you navigate to the login screen, call finish() on the first screen

一直在等你来 2024-12-20 15:13:03

阅读 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文