android:暂停一个活动直到另一个活动完成
当我的应用程序启动时,它会检查是否已存储登录凭据。如果没有,它会启动另一个活动来提示用户输入这些凭据。我的问题是,当提示活动启动时,第一个活动继续执行并以空指针结束,因为提示活动尚未返回所需的数据,
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的“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.
在promptForLoginInfo()中;你需要启动activityForResult。
那么你需要移动displayCredentials();从 onCreate 到 onActivityResult
In promptForLoginInfo(); you need to start activityForResult.
then you need move displayCredentials(); from onCreate to onActivityResult
您是否尝试在调用 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().