Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pakoito/cc1d37da62d01648bde0 to your computer and use it in GitHub Desktop.
Save pakoito/cc1d37da62d01648bde0 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)

onStart

onStop

  • EventBus unregister

onDestroy

  • Dagger "Activity" scoped graph destruction

Fragment

onCreateView

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

onStart

  • EventBus register

onStop

  • EventBus unregister

onDestroy

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

View

onAttachedToWindow

  • RxJava CompositeSubscription.add

onDetachedFromWindow

  • RxJava CompositeSubscription.unsubscribe

Application

  • LeakCanary Refwatcher = LeakCanary.install(this);
  • Dagger ObjectGraph.create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment