Today you will create your first multi-screen applications using Intents and Fragments.
An Activity
is started or activated with an intent. An Intent
is an asynchronous message that you can use in your Activity
to request an action from another Activity
, or from some other app component. You use an Intent
to start one Activity
from another Activity
, and to pass data between activities.
A Fragment
is a self-contained component with its own user interface (UI) and lifecycle that can be reused in different parts of an app's UI, which can be used to give the impression of swapping between various screens of an application.
Activity
in Android Studio.Activity
with an explicit Intent
.Activity
with an explicit Intent
.Intent
to invoke actions.Activity
expecting results back.Intent
.permissions
.Fragment
to the layout of an Activity
.Fragment
while an Activity
is running.Create a blank app with an empty Activity
. Add four new activities to the app. Navigate to the AndroidManifest.xml
file under the app>manifest folders in the project directory. How does the file change as you add more activities to the app?
Create an app which displays a Button
. Clicking the Button
should send an explicit Intent
to start a new Activity
within the app.
Extend your app from the previous exercise to also send data along with the Intent
, gathered from an EditText
field. Have the second Activity
retrieve this data and display it on the screen.
Extend your app from previous exercise to have the second Activity
send a reply back to the first Activity
. Display the reply in the first Activity
.
Create an app which uses an implicit Intent
to send an email. Have the Intent
contain information for receiver email, subject and a text body.
Implement an app that registers itself as a web browser so that it can display web pages for other apps. Have the app show a requested web page in a WebView
through an implicit Intent
.
Create a "single Activity application" that uses the FragmentManager
to swap between fragments in a container.
If you have time left, try to refactor the previous exercise to use the navigation component instead. This component acts as an abstraction on top of the navigation you have implemented so far, simplifying the implementation as well as adding various navigation features such as transitions, navigation graph overview and automatic handling of the backstack. It will be very useful when utilizing components such as Navigation Drawers, Bottom Navigation Bars and similar premade UI components, since they work with the Navigation Component out of the box.