Reputation: 6165
I am using Facebook SDK to create a simple Facebook log in application. I created a new app and added Facebook SDK in library. According to instruction given by Facebook i have added this code :
@Override
protected void onResume() {
super.onResume();
AppEventsLogger.activateApp(this);
}
but along with this i need to add deactivation code as well, so i added this code :
@Override
protected void onPause() {
super.onPause();
AppEventsLogger.deactivateApp(this);
}
Here 'AppEventsLogger.deactivateApp(this);' is showing error "The method deactivateApp(MainActivity) is undefined for the type AppEventsLogger". Can any one help.
Upvotes: 2
Views: 609
Reputation: 401
You need to initialize
Facebook SDK before you can use it. Add a call to FacebookSdk.sdkInitialize
from onCreate
in Activity or Application:
// Add this to the header of your file:
import com.facebook.FacebookSdk;
// Updated your class body:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
// Initialize the SDK before executing any other operations,
// especially, if you're using Facebook UI elements.
}
Add a uses-permission
element to the manifest:
<uses-permission android:name="android.permission.INTERNET"/>
Add a meta-data
element to the application
element:
<application android:label="@string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
...
</application>
Using Login or Share
To use Facebook Login or Share, also add the FacebookActivity
to the manifest:
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
Check out this link Getting Started Android SDK
Upvotes: 1