Issue
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?
Solution
Would be something like:
onCreate:
findViewByIdlookups- Setup views listeners
- Open database connections
- Initialize third party libraries
- Initialize Loaders
- Open files
onStart:
- Open remote resources
- Register BroadcastReceivers
onResume:
- Initialize animations
onPause:
- Get ready to save variables in the onSaveInstanceState bundle
- Start clearing resources if isFinishing is true.
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)
Answered By - Evin1_
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.