Activity 调用第二个 Activity,但在第二个 Activity 调用 onCreate() 之前返回结果?
我这里需要一些帮助。基本上,我有一个活动。这使用 startActivityForResult()
方法调用第二个 Activity(属于同一应用程序的一部分)。在调用第二个 Activity 的 onCreate()
方法之前,第二个 Activity 的结果代码返回 RESULT_CANCEL
。
这让我很困惑。如果我更改 Intent 并调用 Android Messaging App Activity 而不是我自己的 Activity,我会在该 Activity 完成后正确地获取结果代码。
对我来说很明显,当您调用自己的 Activity 以获得结果时,您必须做一些不同的事情。
在Android V2.2上测试
I need some help here. Basically, I have an Activity. This uses the startActivityForResult()
method to call a second Activity (which is part of the same app). The result code for this second Activity returns RESULT_CANCEL
before the onCreate()
method of the second Activity is called.
This is bewildering me. If I change the Intent and call the Android Messaging App Activity and not my own Activity I get the result code correctly after that Activity finishes.
It's pretty obvious to me that when you call your own Activity for a result you must do something different.
Testing on Android V2.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最初的想法是尝试在 Android 清单中使用意图过滤器,并将意图限制为您试图从中获取结果的单个活动。
我希望这能回答您的问题!
My initial thought is to try using an Intent Filter in your Android manifest and limiting the intents to the single activity you're trying to get a result from.
I hope this answers your question!
好的,所以我已经找到了解决方案。
如果您的 launchMode 为“singleTask”或“singleInstance”,则您无法从应用程序启动的 Activity 接收结果。它将立即返回为 RESULT_CANCEL。通过将 Activity 的 launchMode 更改为“standard”或“singleTop”,这个问题就得到了解决。
示例:
而不是
我希望这可以帮助任何有同样问题的人。
Ok, so I have found the solution to this.
If you have a launchMode of "singleTask" or "singleInstance" then you cannot receive a result from an Activity that you launch from your application. It will return immediately as RESULT_CANCEL. By changing the launchMode of the Activity to "standard" or "singleTop" this problem is solved.
example:
instead of
I hope this helps out anyone who has the same problem.