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

前端之家收集整理的这篇文章主要介绍了android – onNewIntent(intent)不能正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在构建这个twitter应用程序,浏览器被调用以从我的主要活动进行身份验证.
在线程中运行以下代码(AsyncTask)
  1. 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);
  2. context.startActivity(intent);

这里

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

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

我在用

  1. @Override
  2. public void onNewIntent(Intent intent) {
  3. super.onNewIntent(intent);
  4. SharedPreferences prefs = getSharedPreferences("twitter",0);
  5. final Uri uri = intent.getData();
  6. if (uri != null && uri.getScheme().equals(Constants.OAUTH_CALLBACK_SCHEME)) {
  7.  
  8. setLoggedIn(true,tlogout);
  9. tstatus=true;
  10.  
  11. new RetrieveAccessTokenTask(this,consumer,provider,prefs,tstring).execute(uri);
  12.  
  13. }
  14. }

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

我的清单是

  1. <activity
  2. android:name=".mainActivity"
  3.  
  4. android:launchMode="singleTask"
  5.  
  6. android:label="@string/title_activity_main" >
  7. <intent-filter>
  8. <action android:name="android.intent.action.VIEW" />
  9. <category android:name="android.intent.category.DEFAULT" />
  10. <category android:name="android.intent.category.BROWSABLE" />
  11. <data android:scheme="x-oauthflow-twitter" android:host="callback" />
  12.  
  13. </intent-filter>
  14. </activity>

解决方法

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

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

猜你在找的Android相关文章