Created
November 5, 2014 13:00
-
-
Save geftimov/bdd041c42837bd9f6c93 to your computer and use it in GitHub Desktop.
BaseFragment Otto and Dagger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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