- In general you want to try and put things in
onStart
andonStop
for logical start and stops.
- Dagger inject self into graph
- setContentView(R.layout.xxx)
- Butterknife.bind(this)
- RxJava CompositeSubscription.add (if NON UI related work being done)
- realm = Realm.getDefaultInstance();
- EventBus register // why not onResume + onPause you ask?
- RxJava CompositeSubscription.add (if ui related work being done)
- RxJava CompositeSubscription.clear (if ui related work being done)
- EventBus unregister
- Dagger "Activity" scoped graph destruction
- RxJava CompositeSubscription.clear (if NON UI related work being done)
- realm.close();
- Dagger inject self into graph
- setCallbackOrListener(activity) - when you want to communicate back to the activity
Warning: lifecycle callpoint is subtly different now. onAttach(Context) is called later than onAttach(Activity) and so if you expected the injection to have happened before certain callbacks like onViewCreated this is not the case (e.g. API 19)
- view = Inflate.inflation
- ButterKnife.bind(this, view);
- realm = Realm.getDefaultInstance();
- EventBus register
- RxJava CompositeSubscription.add (if ui related work being done)
- RxJava CompositeSubscription.clear (if ui related work being done)
- EventBus unregister
- LeakCanary MyApp.getRefWatcher().watch(this);
- ButterKnife.unbind(this);
- realm.close();
- Butterknife.bind(this)
- RxJava CompositeSubscription.add
- RxJava CompositeSubscription.clear
- LeakCanary Refwatcher = LeakCanary.install(this);
- Dagger ObjectGraph.create
- Butterknife.bind(this. itemView)
@konmik very interesting. The counter to having it in
onResume
is the case where you have a dialog show up in front of the activity.onPause
would be fired and the event bus would stop listening to future events in that activity.question: how often though do you think we would get an important event fired between
onStart
andonRestoreInstanceState
? The counter point i brought up is possibly more plausible?I see your point too though. I guess we pick the lesser of two evils :( ?