微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – onNewIntent(intent)不能正常工作

我正在构建这个twitter应用程序,浏览器被调用以从我的主要活动进行身份验证.
在线程中运行以下代码(AsyncTask)
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
context.startActivity(intent);

这里

context is the context of main activity..the uri is returned through `intent`..

认证后要做的是回到我的主要活动,到现在的状态.
现在发生的是,它创造了另一个主要活动的实例.

我在用

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent); 
    SharedPreferences prefs = getSharedPreferences("twitter",0);
    final Uri uri = intent.getData();
    if (uri != null && uri.getScheme().equals(Constants.OAUTH_CALLBACK_SCHEME)) {

        setLoggedIn(true,tlogout);
        tstatus=true;

        new RetrieveAccesstokenTask(this,consumer,provider,prefs,tstring).execute(uri);

    }
}

但仍然存在问题,另一件事是,仿真器中的一切都很好(2.3)..
不能在我的设备上工作Android 2.3.6

我的清单是

<activity
    android:name=".mainActivity"

    android:launchMode="singleTask"

    android:label="@string/title_activity_main" >
    <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="x-oauthflow-twitter" android:host="callback" />

    </intent-filter>
</activity>

解决方法

我不熟悉Twitter验证过程,但您可以尝试使用FLAG_ACTIVITY_CLEAR_TOP而不是Intent.FLAG_ACTIVITY_SINGLE_TOP.

后者仅适用于您,如果您的主要活动位于堆栈顶部,则另一个清除堆栈并确保您的活动位于顶部.

原文地址:https://www.jb51.cc/android/313290.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐