Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mistrydarshan99/f4b0ba4b912a1109e29e003aa0555cd9 to your computer and use it in GitHub Desktop.
Save mistrydarshan99/f4b0ba4b912a1109e29e003aa0555cd9 to your computer and use it in GitHub Desktop.
Notes on opportune moments to do "stuff" in the Android Lifecycle
  • In general you want to try and put things in onStart and onStop for logical start and stops.

Activity

onCreate

  • Dagger inject self into graph
  • setContentView(R.layout.xxx)
  • Butterknife.bind(this)
  • RxJava CompositeSubscription.add (if NON UI related work being done)

onStart

onResume

  • RxJava CompositeSubscription.add (if ui related work being done)

onPause

  • RxJava CompositeSubscription.clear (if ui related work being done)

onStop

  • EventBus unregister

onDestroy

  • Dagger "Activity" scoped graph destruction
  • RxJava CompositeSubscription.clear (if NON UI related work being done)

Fragment (DialogFragment etc.)

onAttach(Activity)

  • Dagger inject self into graph
  • setCallbackOrListener(activity) - when you want to communicate back to the activity

onCreateView

  • view = Inflate.inflation
  • ButterKnife.bind(this, view);

onStart

  • EventBus register

onResume

  • RxJava CompositeSubscription.add (if ui related work being done)

onPause

  • RxJava CompositeSubscription.clear (if ui related work being done)

onStop

  • EventBus unregister

onDestroy

  • ButterKnife.unbind(this);
  • LeakCanary MyApp.getRefWatcher().watch(this);

View

onFinishInflate

  • Butterknife.bind(this)

onAttachedToWindow

  • RxJava CompositeSubscription.add

onDetachedFromWindow

  • RxJava CompositeSubscription.clear

Application

  • LeakCanary Refwatcher = LeakCanary.install(this);
  • Dagger ObjectGraph.create

ViewHolder (for RecyclerViews, ListViews etc.)

ViewHolder (Constructor)

  • Butterknife.bind(this. itemView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment