Activity :-
An Activity is a user interface screen . Application can contain one or more activities to handle different phases of the program. It is the entry point of an android App. Activity is alive i.e. each activity is responsible for saving its own state.
To create activity first create a class as a child of android.app.Activity class.
Activity Life Cycle :-
Activity having four 4 states
1) Doesn't exist state
2) Foreground state
3)Pause state
4)Background state
Activity goes through several states by using following major methods
1) onCreate() :-
This is called when the activity first starts up. You can use it to perform one-time initialization such as creating the user interface. oncreate() takes one parameter that is either null or some state information.
2)onStart() :- This indicate the activity is about to be displayed to the user.
3)onResume() :- This is called when your activity can start interacting with the user.
4) onPause():- This runs when the activity is about to go into the background.
5)onStop() :- This is called when your activity is no longer visible to the user and it won't be needed for a while.
6) onRestart() :- If this method is called , it indicates your activity is being redisplayed to the user from a stopped state.
7) onDestroy() :- This is called right before your activity is destroyed. if memory is tight ,onDestroy() may never be called (the system may simply terminate your process).
1 Comments