I have created an abstract class FbActivity, which extends Activity to connect to facebook using Facebook's SDK for Android. Something like the following:
public abstract class FbActivity extends Activity {
private static final String APP_ID = "xxxxxxxxxxxxx";
protected Facebook mFacebook;
/*
* Override onCreate to connect to facebook.
*/
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFacebook = new Facebook(APP_ID);
setFbConnection();
}
Do I want each FbActivity
instantiate their own Facebook variable, or should I make the Facebook variable static
, so there is only one variable for the entire application? Or perhaps I should use a singleton
type of setup like the following...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mFacebook == null) {
mFacebook = new Facebook(APP_ID);
}
setFbConnection();
}
If you do not have an answer to this exact question, then abstract away from the Facebook variable. When is it "better" to have a static variable (especially in inheritance situations like this)?