我正在构建这个twitter应用程序,浏览器被调用以从我的主要活动进行身份验证.
在线程中运行以下代码(AsyncTask)
在线程中运行以下代码(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.
后者仅适用于您,如果您的主要活动位于堆栈顶部,则另一个清除堆栈并确保您的活动位于顶部.