In this tutorial we will learn to create a project in android and see how the activity life cycle works. We will also see how to create toast using activity life cycle. For android project creation you need JDK & Eclipse.
Download Android Studio and SDK:
Let us get started.
Step 1: Choosing a New Project
Click on new file option and select new project option.
Step 2: Choose Android Project
Next click on android application project option.
Step 3: Add App Name and Package Name
After selection you will see the option as shown below and then you can name your project & than give application a package name.
Then click to Next option.
Step 4: Configure Launcher Icon
Then click Next button. Here you can select your app icon and select app icon background and its foreground scaling.
Step 5: Select Activity Template
After that you will able to select activity option here we need to select blank activity option we’ll discuss other option later.
Step 6: Configure Activity
After that you will able to give your activity name and you xml layout name. You can give any custom name to your class and layout here I am using the default name.
Finish this project and you will see your MyApplication has been created. After that open MainActivity class and here you will see in this class Activity is extended in your class which is super class. For activity life cycle you need to extend this class into your class.
Note, that for running your project you need one activity class & you need to define in manifest file and name that file main intent filter:- This is the activity that will be run initially.
You define you can layout in XML file. Here in this class you are seeing onCreate() method which run first and all view & widget are setup here. Here we have set main_activity view by using setContentView() method. Now we are overriding all activity life cycle methods by
In your activity right click anywhere and you will see Source option then select Override/Implement Methods.
Now you will see all life cycle method and other object class method which you can override methods here I am selecting:
onDestroy(). In all method I am declaring Toast. Its a small time event for showing messages. Now after running your project you will methods occurrence. All methods execute in sequence .
In this tutorial you learnt how to setup your project using Eclipse.
This content has been helpful to you?
Thanks for contributing!