Android Javascript Ajax Html PHP Example

Android Life Cycle


So before proceeding towards the android example let’s find out the flow chart of the android life cycle.

The Activity class provides a number of callbacks that allow the activity to know that a state has been changed: that the system is creating, stopping, or resuming an activity, or destroying the process in which the activity resides.

when the system first launches the activity, you must implement the onCreate method.

Inside this onCreate method, you perform a basic operation that should happen only once for the entire life of the activity.

After the onCreate method activity enters the started state and the system calls the onStart method.

In the onStart method, activity is visible to the user and it prepares the activity to enter the foreground and become interactive, where the app initializes the code that maintains the UI and once, when this callback finishes, the activity enters the onResume state.

When the activity enters the resumed state, it comes to the foreground. This is a state in which the app interacts with the users. It keeps active until something happens to take focus away from the activity.

For example: To navigate another activity

receiving a phone call
or the device screen turns off.

If another activity comes to the foreground then onPause method is called and it performs when the activity enters into the resumed state.

If the shorter span of time activity navigates to the same activity then it calls the onResume method.

If the activity is no longer active or about to terminate, the system calls the onStop method,

At the onStop method, there are two conditions, when the other application has opened, then the processor tries to kill the app, to free the memory.

If your app doesn’t kill the processor, then it navigates you to the restart method which calls the onStart method then it goes in the same as well.

And when the processor kills the app to free the memory, then it navigates you to the onCreate method.

If your app is closed or shut down by the user then it calls the onDestroy method.

Inside this event, the activity is finished due to the finish method being called on the activity.

And then the activity closed.