Switching Activities in Android Studio: Android Programming @DrBFraser
Switching Activities in Android Studio: Android Programming  @DrBFraser
Uploaded January 2017 | Updated November 2026, 3 hours ago
Create and launch a second Android activity. Covers Intent, startActivity(), finish(), and the activity stack.

For tutorial on creating a button, see youtube.com/watch?v=aE5f1tV5nU4

Initial setup:
--------------------
Have project with initial activity and button for Toast

Create new activity: SecondActivity
--------------------
Show .xml, .java, and manifest.

Launch activity:
--------------------
startActivity(new Intent( [Current Activity's 'this'], [New Activity's Java].class));

Encapsulate launching
--------------------
Intent i = SecondClass.makeIntent(this)
startActivity();

Activity Stack
--------------------
- Loading an Activity pushes it on the Activity *Stack*
- Pressing back button pops stack:
destroys this activity, returns to previous activity.
- New Button runs activity's finish() method pops it in code.
Must use correctly to have good activity stack.
If you instead startActivity() back to the first one, you make a loop.

Can move on and kill current activity:
--------------------
startActivity(...);
finish();

Troubleshooting:
--------------------
- Demonstrate what happens with the activity being in the manifest.
* View LogCat via DDMS:
...android.content.ActivityNotFoundException: Unable to find explicit activity class ...; have you declared this activity in your AndroidManifest.xml?
Switching Activities in Android Studio: Android ProgrammingInstall and Run C++ in Visual Studio Code (Linux)Python in VS Code - Very Basics!Plain Java & JUnit 5 in Android StudioLocking Activity Orientation: Android ProgrammingJUnit 4 with IntelliJ: A quick introductionGit Overview: Git & EclipseEditText and TextView: Android ProgrammingC Makefile Project in Eclipse under LinuxMutex Synchronization in Linux with PthreadsIntroduction to JUnit 5C++ File Input / Output
Brian Fraser |

Switching Activities in Android Studio: Android Programming

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER