我在FacebookSdk.sdkInitialize(getApplicationContext())
中致电GlobalActivity
。
public class GlobalActivity extends Application {
@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
每次使用facebook sdk时,是否需要再次调用它?
我有一个Fragment
LoginButton
。
public class LoginFragment extends Fragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
}
}
答案 0 :(得分:1)
简单的方法是在Application类中初始化一次就够了。当新活动创建FacebookSdk时自动初始化。
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
public class ApplicationName extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}