Socialize Lifecycle
Socialize must be bound to the lifecycle of each Activity in which you want to include Socialize functionality.
This is to ensure that all resources used by Socialize are effectively cleaned up as well as important tasks like Facebook token refreshing
are performed when they should be.
import android.app.Activity;
import android.os.Bundle;
import com.socialize.Socialize;
public class SampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Call Socialize in onCreate
Socialize.onCreate(this, savedInstanceState);
}
@Override
protected void onPause() {
super.onPause();
// Call Socialize in onPause
Socialize.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
// Call Socialize in onResume
Socialize.onResume(this);
}
@Override
protected void onStart() {
super.onStart();
// Call Socialize in onStart
Socialize.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
// Call Socialize in onStop
Socialize.onStop(this);
}
@Override
protected void onDestroy() {
// Call Socialize in onDestroy before the activity is destroyed
Socialize.onDestroy(this);
super.onDestroy();
}
}
Intercepting Socialize Activity Lifecycle Events
|
Advanced Use
|
The following section is not required if you are simply using the Action Bar
If you want to override the default behavior of an activity that is managed by Socialize you can inject a SocializeActivityLifecycleListener
into the Socialize singleton instance.
Note
This is a global setting. The listener will be called for ALL Socialize activities.
import android.app.Activity;
import android.os.Bundle;
import com.socialize.Socialize;
import com.socialize.ui.DefaultSocializeActivityLifecycleListener;
import com.socialize.ui.SocializeUIActivity;
public class SampleActivityWithListener extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set a lifecycle listener
Socialize.setSocializeActivityLifecycleListener(new DefaultSocializeActivityLifecycleListener() {
@Override
public void onPause(SocializeUIActivity activity) {
// Add your code here
}
@Override
public void onResume(SocializeUIActivity activity) {
// Add your code here
}
// Implement other methods as required
});
// Call Socialize in onCreate
Socialize.onCreate(this, savedInstanceState);
}
@Override
protected void onPause() {
super.onPause();
// Call Socialize in onPause
Socialize.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
// Call Socialize in onResume
Socialize.onResume(this);
}
@Override
protected void onStart() {
super.onStart();
// Call Socialize in onStart
Socialize.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
// Call Socialize in onStop
Socialize.onStop(this);
}
@Override
protected void onDestroy() {
// Call Socialize in onDestroy before the activity is destroyed
Socialize.onDestroy(this);
super.onDestroy();
}
}
Socialize Lifecycle¶
Socialize must be bound to the lifecycle of each Activity in which you want to include Socialize functionality.
This is to ensure that all resources used by Socialize are effectively cleaned up as well as important tasks like Facebook token refreshing are performed when they should be.
Intercepting Socialize Activity Lifecycle Events¶
If you want to override the default behavior of an activity that is managed by Socialize you can inject a SocializeActivityLifecycleListener into the Socialize singleton instance.
Note
This is a global setting. The listener will be called for ALL Socialize activities.