Practical 3 : Android App Life Cycle of Two Activities - IndianTechnoEra
Latest update Android YouTube

Practical 3 : Android App Life Cycle of Two Activities

Android App Life Cycle of Two Activities

 Aim: 

Write a program to study the life cycle of two activities.

In this practical there will be define two different pages and then both pages will be connected with each other like suppose one page is the first page and another page is the second page and on the clicking on the button of first page we will move to another page

Android App Life Cycle of Two Activities | IndianTechnoEra


Process

After create the project we will get one My_Activity.java and activity_main.xml file default

Drag one button upon the first page activity_main.xml then give a name to the button and give an onClick event then go to the code form of UI and press ‘Alt+Enter’  just right of the onClick function name and Create related activity in Main_Activity.java. 

Another way to give the elements name from string.xml file as <string name=”btnName”> Go to second page </string> in between <resources> tag.  And there after assign the value to the element in activity_main.xml file as “@string/btnName


Define all the activity methods as the first practical in activity one.

Then create new activity by following the given steps 

right click on MainActivity.java folder >> New >> Activity >> Basic Activity >> give name >> ok


A new Main_Activity.xml will create and also another activity_main2.xml file will create in layout folder for UI part of second activity.

The a new activity_main2.xml will be create automatic

Then here also define all the endowed methods activity. As the name a second phase. Like on Pause First page, on Start, Pause page, on desktop page, on resume, post pairs like.


Then on the method of button, create an intent in Main_Activity.java and pass the value of 2nd activity UI 


Code:

MainActivity.java for program of the first activity

MainActivity2.java for program of the second page activity

activity_main.xml for the UI part of the first page that will be handle by the first activity

activity_main2.xml for the UI part of the second page that will appear for the second page


MainActivity.java


MainActivity2.java


activity_main.xml


activity_main2.xml


Output:


Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.