这是我的活动:
import com.apprikot.kooora.controller.interfaces.HasTwitter;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
public class SocialActivity extends BaseActivity implements HasTwitter {
protected CallbackManager mCallbackManager;
protected TwitterAuthClient mTwitterAuthClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create();
mTwitterAuthClient = new TwitterAuthClient();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
mTwitterAuthClient.onActivityResult(requestCode, resultCode, data);
}
@Override
public TwitterAuthClient getTwitterAuthClient() {
return mTwitterAuthClient;
}
}
与我无关的简单解决方案是将初始化放在setContentView
之前,这已在我的案例中完成。
这是主要的活动清单声明(它扩展了上面的SocialActivity):
<activity
android:name=".controller.activities.MainActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan"/>
最后,这是我得到的崩溃:
java.lang.RuntimeException:无法恢复活动{com.sikooora / com.facebook.FacebookActivity}:SDK尚未初始化,请务必先调用FacebookSdk.sdkInitialize()。\ n \ tat android.app .ActivityThread.performResumeActivity(ActivityThread.java:2853)\ n \ tat android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2882)\ n \ tat android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2314)\ n \ tat android.app.ActivityThread.access $ 700(ActivityThread.java:157)\ n \ tat android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1289)\ n \ tat android.os.Handler.dispatchMessage(Handler。 java:99)\ n \ tat android.os.Looper.loop(Looper.java:176)\ n \ tat android.app.ActivityThread.main(ActivityThread.java:5317) \ n \ tat java.lang.reflect。 Method.invokeNative(Native Method)\ n \ tat java.lang.reflect.Method.invoke(Method.java:511)\ n \ tat com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1102 )\ n \ tat com.android.internal.os.ZygoteInit.main(ZygoteInit) .java:869)\ n \ tat dalvik.system.NativeStart.main(Native Method)\ n原因:SDK尚未初始化,请务必先调用FacebookSdk.sdkInitialize()。\ n \ tat com.facebook。 internal.Validate.sdkInitialized(Validate.java:136)\ n \ tat com.facebook.FacebookSdk.getApplicationContext(FacebookSdk.java:427)\ n \ tat com.facebook.AccessTokenManager.getInstance(AccessTokenManager.java:84)\ n \ tat com.facebook.AccessToken.getCurrentAccessToken(AccessToken.java:144)\ n \ tat com.facebook.login.LoginClient.authorize(LoginClient.java:121)\ n \ tat com.facebook.login.LoginClient.startOrContinueAuth( LoginClient.java:108)\n\tat com.facebook.login.LoginFragment.onResume(LoginFragment.java:152)\ n \ tat android.support.v4.app.Fragment.performResume(Fragment.java:2020)\ n \ tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1107)\ n \ tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)\ n \ tat android.support。 v4.app.FragmentManagerImpl.moveToState(FragmentMa nager.java:1234)\n\tat android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2056)\ n \ tat android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:196) \ n \ tat android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:505)\ n \ tat android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:494)\ n \ tat android。 app.Activity.performResume(Activity.java:5417)\ n \ tat android.app.ActivityThread.performResumeActivity(ActivityThread.java:2830)