webnovel

activity & lifestyle

Android activity & Activity Lifecycle |

In layman language activity can be explained as a screen which we see when we open an application and we navigate from one activity to another by click on buttons.

It is the activity that we interact with , when we open our application. suppose you share the video of codewithharry channel on youtube to your friends  than you click on share and it will navigatwe you to the whatsapp (another activity). An appliation has atleast has one activity .

 An activity has various stages in its lifecycle.To transit from one stage to the other stage of the activity lifecycle activity class has six methods which are overrided by the developers according to the need.These methods are termed as callbacks. The six callbacks are :

 onCreate(): It displays the UI given in the XML file when the activity starts . It calls the SetContentView() method.

onStart(): when our activity is in process to be displayed this callback method is called .And after this method onResume() callback is called.

onResume() :The core functionality of application is written within this callback method.When the activity is just about to be displayed this callback method is called .Suppose if you start a new activity that hides the already ongoing activity , onResume() is called when the activity that was hidden comes back to the view on the screen again.

onPause(): The code you want to be executed when app is being paused (minimised ) should be wriiten in this callback method and when the user resumes to the application onResume() callback method will be called again.

onStop(): when an activity is being minimised onPause() callback is immediately called and after a few miliseconds onStop will be called.onStop() will stop the API calls of the application.

onDestroy(): onDestroy callback is to be called when you need to shutdown all the operations .

onPause(), onStop() & onDestroy() are three callback methods which are called while our activity is being launched. Every Android project must have AndroidManifest.xml . And it contains the information regarding the packages , class names , the permissions that app needs,hardware and software features that app requires for the device in which it will be installed . All the information regarding how app is being structured is within this file.

No Source Code Associated With This Video