Skip to content

Instantly share code, notes, and snippets.

@geftimov
Created November 5, 2014 12:59
Show Gist options
  • Save geftimov/304863eded96f8e79108 to your computer and use it in GitHub Desktop.
Save geftimov/304863eded96f8e79108 to your computer and use it in GitHub Desktop.
BaseActivity Otto and Dagger
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import com.eftimoff.jokes.JokesApplication;
import com.eftimoff.jokes.utils.SharedPrefs;
import com.squareup.otto.Bus;
import javax.inject.Inject;
public class BaseActivity extends ActionBarActivity {
@Inject
SharedPrefs sharedPrefs;
@Inject
Bus bus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Perform injection so that when this call returns all dependencies will be available for use.
JokesApplication.inject(this);
bus.register(this);
}
@Override
protected void onResume() {
super.onResume();
bus.register(this);
}
@Override
protected void onPause() {
super.onPause();
bus.unregister(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment