android:暂停一个活动直到另一个活动完成

发布于 2024-09-01 19:05:35 字数 479 浏览 11 评论 0原文

当我的应用程序启动时,它会检查是否已存储登录凭据。如果没有,它会启动另一个活动来提示用户输入这些凭据。我的问题是,当提示活动启动时,第一个活动继续执行并以空指针结束,因为提示活动尚未返回所需的数据,

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tv = new TextView(this);
    setContentView(tv);

    promptForLoginInfo(); //method creates intent and starts activity

    displayCredentials(); //prints data to screen
}

输出读取:“null”,因为程序执行“displayCredentials()”在登录提示活动返回之前。

有人知道该怎么做吗?

When my app starts, it checks to see if it has stored login credentials. if it doesn't, it starts another activity to prompt the user for those credentials. My problem is, that when the prompt activity is started, the first activity continues execution and ends up with null pointers because the prompt activity has not yet returned the needed data

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tv = new TextView(this);
    setContentView(tv);

    promptForLoginInfo(); //method creates intent and starts activity

    displayCredentials(); //prints data to screen
}

the output reads: "null" because the program executes "displayCredentials()" before the login prompt activity returns.

Anyone have a clue what to do?

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

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

发布评论

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

评论(3

倚栏听风 2024-09-08 19:05:35

您的“promptForLoginInfo()”方法应该调用 startActivityForResult。您的“displayCredentials()”方法不应在 onCreate() 方法中调用,而应在 onActivityResult 方法。

Your "promptForLoginInfo()" method should be calling startActivityForResult. Your "displayCredentials()" method should not be called in the onCreate() method, but in the onActivityResult method.

独留℉清风醉 2024-09-08 19:05:35

在promptForLoginInfo()中;你需要启动activityForResult。
那么你需要移动displayCredentials();从 onCreate 到 onActivityResult

In promptForLoginInfo(); you need to start activityForResult.
then you need move displayCredentials(); from onCreate to onActivityResult

心如荒岛 2024-09-08 19:05:35

您是否尝试在调用 displayCredentials() 之前检查存储的凭据?如果未找到凭据,您可以通过 startActivityForResult() 方法启动活动,并在 onActivityResult() 中的提示活动完成后调用 displayCredentials()。

Did you tried to check for stored credentials before calling displayCredentials()? If credentials are not found you can start activity by startActivityForResult() method and call displayCredentials() after your prompt activity finishes in onActivityResult().

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