- 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)
@ar-g : hmm... I hesitate to put it as a general rule in here.
If you're doing UI related stuff with your Subscriptions, then sure
onResume
<->onPause
may be wise. but if you're doing non-ui related work like network activity, saving to disk etc. other concurrency related activity which RxJava is great at, then evenonCreate
<->onDestroy
might be better.Interesting, maybe UI related events should be classified separately.