带浏览器oauth的Android后退按钮返回浏览器

时间:2012-02-27 04:16:39

标签: android twitter-oauth

第一次发帖提问我道歉,关于这个问题有很多问题,但在尝试了很多不同的选择后,我似乎无法让这个问题起作用。

我有一个Twitter应用程序,主屏幕有一个按钮,通过标准浏览器应用程序请求oauth twitter访问,然后返回到主屏幕。如果我点击后退按钮,浏览器应用程序将打开Twitter网站。我已经在清单文件中尝试了noHistory,并且在许多场景中启动了意图FLAG_ACTIVITY_NO_HISTORY以及FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_SINGLE_TOP而没有运气。

这是我最新的代码:

清单文件

<activity android:name=".oauth" 
                  android:label="@string/oauth_name"
                  android:noHistory="true"
                  >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="tm" android:host="twitt" />

            </intent-filter>
        </activity> 
<activity   android:name="com.tweetymanagerpro.Home" 
                    android:label="@string/app_name"
                    android:theme="@android:style/Theme.NoTitleBar"
                    android:windowSoftInputMode="stateHidden|adjustPan">
                <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                </intent-filter>
          </activity>

在Home活动中,我将oauth称为如下

Intent settingsActivity = new Intent(getBaseContext(), oauth.class);
                settingsActivity.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                startActivity(settingsActivity);

接下来,在oauth.onCreate()中,我呼叫twitter url

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

            this.startActivity(intent);

接下来,在oauth.onResume()中,我处理令牌等,然后再次启动Home

Intent i = new Intent(this, Home.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);

与twitter的连接效果很好,现在就在Home,如果我点击后退按钮,它会将我带回浏览器,并通过Twitter进行身份验证。

2 个答案:

答案 0 :(得分:1)

考虑在您控制的网页浏览中呈现oauth网页,而不是启动浏览器应用。

oauth网页在调用其回调时,实际上将在webview中替换自己,其中WebViewClient可以捕获预期的URL,处理结果,并完成()webview(将其从活动堆栈中删除)

答案 1 :(得分:0)

oauth Activity是实际的浏览器活动吗?如果是这样,您可以在启动Home活动后调用finish(),将其从活动堆栈中删除。

如果没有,也许如果您的家庭活动是从您的oauth活动开始的,那么您的oauth类会在您的意图中添加另一个标记。因此,如果您的家庭班级看到此意图,它可以覆盖BACK键按下而不执行默认操作(完成并恢复到您的浏览器活动)。

相关问题