Android tutorial - Screen Navigation in Android - android app development - android studio - android development tutorial
Learn android - android tutorial - Screen navigation in android - android examples - android programs
Android activity - Navigation from one screen to another screen
- In Android, an activity is representing a single screen.
- Most applications have multiple activities to represent different screens, for example, one activity to display a list of the application settings, another activity to display the application status.
Functionality
- How to interact with activity, when a button is clicked, navigate from current screen (current activity) to another screen (another activity).
1. XML Layouts
Create following two XML layout files in “res/layout/” folder:
- res/layout/main.xml - Represent screen 1
- res/layout/main2.xml - Represent screen 2
Code for the File : res/layout/main.xml
Code for the File : res/layout/main2.xml
2. Activities
Create two activity classes :
- AppActivity.java -> main.xml
- App2Activity.java -> main2.xml
To navigate from one screen to another screen, use following code :
File : AppActivity.java
File : App2Activity.java
3. AndroidManifest.xml
- Declares above two activity classes in AndroidManifest.xml.
File : AndroidManifest.xml
4. Demo - android emulator - android tutorial
- Run application.
- AppActivity.java (main.xml) screen is display.
- When abovebutton is clicked, it will navigate to another screen App2Activity.java (main2.xml).