Skip to content
Coding Fanatic
  • Android Development
  • News and Reviews
  • Road2Pro
  • Tutorials
  • Services
  • About

Setting a Parent Activity, 46/100 Days of Code

  • September 23, 2019September 23, 2019
  • by Richard Clarke

Setting a parent Activity can make your app much more user-friendly.

Simplifying your app’s user interface is one of the great advantages of setting a parent Activity. Today, I show you step by step how to add one to your apps. You can find a video of this at the bottom of the page, a code snippet below, and a link to my source code here.

NOTE: Remember to click Apply Changes in Android Studio to update your emulator!

Beginner: You can download this project from the link above and open it in Android Studio while you follow along with the video.
Advanced: I’ve included steps throughout the page along with code snippets. Feel free to use the video as a reference as well.

Requirements

  • Android Studio and a newly created project with an empty Activity
  • An Android Virtual Device
  • BONUS: An IDE of your preference if you don’t want to use Android Studio to edit your code

Step 1: Update the Second and Third Activity tags with the parentActivityName XML attribute. See the snippet below for the entire AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.clickingactivities">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".Second"
                  android:parentActivityName=".MainActivity"></activity>
        
        <activity android:name=".Third"
                  android:parentActivityName=".MainActivity"></activity>
    </application>

</manifest>

 

It’s that easy! By defining the parent Activity for the Second and Third Activities, the Activities become easier to navigate. To see this in action, watch the YouTube video below.

Join the mailing list to see updates like this every week!
Coding Fanatic

Related

The Activity Stack, 45/100 Days of Code
Switching to OnClickListeners, 47/100 Days of code
Richard Clarke
Richard is currently a developer using Java and Android Studio to build custom applications for Android. Richard tutored in mathematics at Montgomery College, and worked in Information Technology before entering the Software Development industry as a Quality Engineer.
100daysofcode Android AndroidDev Java

Related articles

Your New Favorite Stopwatch App!…
Two for Two BABY! 7…
…But the App is for…
Play Store Blues – 5…
Top 4 Tips for Android…
No Dice – 3 of…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • GitHub
  • YouTube
  • X
  • Instagram
  • LinkedIn
My Tweets

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • X
  • GitHub
  • LinkedIn
  • YouTube

Archives

Theme by Colorlib Powered by WordPress