onResume方法不适用于Twitter实施
问题描述:
试图将Twitter与我的应用程序集成。跟着教程,但它不工作。onResume方法不适用于Twitter实施
我有一个PreferenceActivity
有一个CheckBoxPreference
。如果点击了,我做到以下几点:
chkTwitter.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference _pref) {
Intent fbIntent = new Intent(getApplicationContext(), TwitterConnectActivity.class);
_pref.setIntent(fbIntent);
return false;
}
});
我TwitterConnectActivity被调用时,我配置的Oauth对象那里调用Twitter的认证网站。
当我点击授权应用程序,我onResume
被调用:
@Override
protected void onResume() {
super.onResume();
if (this.getIntent()!=null && this.getIntent().getData()!=null){
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
的问题是,this.getIntent().getData()
是空的,所以我从来不去的,如果条件内。
我AndroidManifest看起来是这样的:
<activity
android:name=".SettingsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<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:host="my_twitter" android:scheme="callback" />
</intent-filter>
</activity>
<activity
android:name=".TwitterConnectActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
十分肯定我定义我的回调URL,如:private String CALLBACK_URL = "callback://my_twitter";
任何人都可以帮我吗?
干杯, 费利佩
答
使用StartActivityForResult代替。
+1教给我一个聪明的小动作,使用点击处理程序动态设置'Preference'的'Intent' :) – Devunwired 2013-03-07 22:27:20
我不知道自己是否对此有信心,因为我没有将Twitter添加到在一段时间的应用程序,但它可能是你需要使用onNewIntent? – Catherine 2013-03-07 22:29:50
很高兴我帮助@Devunwired :) Catherine的oneNewIntent方法将被调用,具体取决于我如何使用launchMode属性,我只是使用正常的,所以我不认为onNewIntent被调用。我会看看! – 2013-03-08 06:30:39