在android中调用Intent.ACTION_VIEW后返回
我的应用程序有 3 个活动 A、B、C。活动 A 调用 B。在 B 中,我调用 Intent.ACTION_VIEW 与 Twitter 进行身份验证,如下所示:
public static void DoAuthen(Context context, String CallBackUrl) throws OAuthMessageSignerException, OAuthNotAuthorizedException,
OAuthExpectationFailedException, OAuthCommunicationException {
httpOauthConsumer = new CommonsHttpOAuthConsumer(context.getString(R.string.Twitter_ConsumerKey), context
.getString(R.string.Twitter_ConsumerSecret));
httpOauthprovider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token", "http://twitter.com/oauth/access_token",
"http://twitter.com/oauth/authorize");
String authUrl = httpOauthprovider.retrieveRequestToken(httpOauthConsumer, CallBackUrl);
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
}
身份验证后,我的应用程序在活动 B 处回调。这里 B 调用 C。 现在,如果我按“后退”按钮,它将导航到浏览器(之前用于通过 Twitter 进行身份验证),而不是先导航到 B,然后导航到 A。 我该如何解决这个问题?
My app has 3 activity A, B, C. Activity A calls B. In B, I call Intent.ACTION_VIEW to do authentication with Twitter as below:
public static void DoAuthen(Context context, String CallBackUrl) throws OAuthMessageSignerException, OAuthNotAuthorizedException,
OAuthExpectationFailedException, OAuthCommunicationException {
httpOauthConsumer = new CommonsHttpOAuthConsumer(context.getString(R.string.Twitter_ConsumerKey), context
.getString(R.string.Twitter_ConsumerSecret));
httpOauthprovider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token", "http://twitter.com/oauth/access_token",
"http://twitter.com/oauth/authorize");
String authUrl = httpOauthprovider.retrieveRequestToken(httpOauthConsumer, CallBackUrl);
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
}
After authentication, My App is called back at activity B. Here B calls C.
Now if I press Back button, it will navigate to browser (which used to authenticate with Twitter before) rather than to B and then to A.
How can I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参考android中的任务和返回堆栈 。您可以在应用程序中使用两个任务 - 第一个任务是处理您的业务,第二个任务是授权。您可以使用意图标志 FLAG_ACTIVITY_NEW_TASK 启动授权并使用参数 android:clearTaskOnLaunch。祝你好运!
Please refer to Tasks and Back stack in android. You can use two tasks in your application - in first one you do your business, in second - authorization. You start authorization with intent flag FLAG_ACTIVITY_NEW_TASK and use parameter android:clearTaskOnLaunch. Good luck!
我将以下标志添加到 ACTION_VIEW 意图中,它解决了返回浏览器问题
I added the following flags to the ACTION_VIEW intent and it solved the going back to browser problem
在 C 中,您可以覆盖后退按钮以直接转到 B
In C you can override back button to go directly to B