2

I am newbie to Android development. I completely understand Android Lifecycle and how each Lifecycle method's purpose is by reading this post.

But what code statements (operations) should normally be implemented in each of these Lifecycle methods (onCreate, onStart, onResume and so on).

For example, I found almost all of UI interactions operations are implemented in onCreate method. I mean linking UI Views by findViewById and define click event listeners on these views by setOnClickListener.

In this phenomenon, what kind of operations are normally done in other Lifecycle methods?

Community
  • 1
  • 1
Steve.NayLinAung
  • 5,086
  • 2
  • 25
  • 49

1 Answers1

2

Would be something like:

onCreate:

  • findViewById lookups
  • Setup views listeners
  • Open database connections
  • Initialize third party libraries
  • Initialize Loaders
  • Open files

onStart:

onResume:

  • Initialize animations

onPause:

onStop:

  • Unregister BroadcastReceivers
  • Close cursors
  • Close remote resources
  • Close files
  • Clear heavy references (Bitmaps/Videos)
  • Clear WebView cache
  • Release MediaPlayer references.

onDestroy:

  • Clear references to everything else (wouldn't be called in some cases)
Evin1_
  • 12,292
  • 9
  • 45
  • 47