Skip to content

Instantly share code, notes, and snippets.

@geftimov
Created November 5, 2014 13:00
Show Gist options
  • Save geftimov/bdd041c42837bd9f6c93 to your computer and use it in GitHub Desktop.
Save geftimov/bdd041c42837bd9f6c93 to your computer and use it in GitHub Desktop.
BaseFragment Otto and Dagger
import android.app.Activity;
import android.support.v4.app.Fragment;
import com.eftimoff.jokes.JokesApplication;
import com.eftimoff.jokes.utils.SharedPrefs;
import com.squareup.otto.Bus;
import javax.inject.Inject;
import butterknife.ButterKnife;
public class BaseFragment extends Fragment {
@Inject
Bus bus;
@Inject
SharedPrefs sharedPrefs;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Perform injection so that when this call returns all dependencies will be available for use.
JokesApplication.inject(this);
bus.register(this);
}
@Override
public void onResume() {
super.onResume();
bus.register(this);
}
@Override
public void onPause() {
super.onPause();
bus.unregister(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.reset(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment