将 Android 活动从后台线程置于前台
我有一个通过 Intent 启动系统浏览器的活动。在此之前不久,我对其他 URL 执行了 HTTP GET。用户在浏览器中完成任务(使用 OAuth 登录)后,将立即响应此 GET。
我希望能够关闭浏览器和/或让我的应用程序的活动回到前面。
我不想使用 WebView,因为我想避免别人认为我可能试图监视密码。
知道如何解决这个问题吗?有可能吗?
非常感谢!
丹尼尔
I have an activity that starts the system browser via Intent. Short before it does that I do a HTTP GET to some other URL. This GET will be answered as soon as the user finishes his task in the browser (logging in using OAuth).
I'd like to be able to close down the browser and / or get my application's activity back to the front.
I do not want to use a WebView because I'd like to avoid the perception that I might be trying to spy on passwords.
Any idea how to solve this? Is it possible at all?
Thanks a bunch!
Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保 OAuth 打开类似于 yourapp://success 的 URL
接下来,添加一个意图过滤器来处理此自定义协议和地址。更多详细信息请参见 http://developer.android.com/guide /topics/intents/intents-filters.html#ifs
Make sure OAuth opens up URL which is something like yourapp://success
Next you add a intent filter to handle this custom protocol and address. More details are at http://developer.android.com/guide/topics/intents/intents-filters.html#ifs
这就是我的项目中的窍门。
应用程序清单非常标准:
这是后台线程的代码片段,用于发送重新显示活动的意图:
请注意,技巧在
MainActivity.getContext().getApplicationContext().startActivity(intent) 中;
部分(上面最后一行)。在 MainActivity 中,我添加了
getContext
方法:并且在“onCreate”中设置了成员“mInstance”:
Here's what did the trick in my project.
The application manifest is pretty standard:
Here's a code snippet of the background thread that sends the intent to re-show the activity:
Note that the trick is in the
MainActivity.getContext().getApplicationContext().startActivity(intent);
part (last line above).In the MainActivity, I added the
getContext
method:And the member 'mInstance' is set in the 'onCreate':