74,490 views 246 on YTPak
375 4

Published on 05 Feb 2013 | over 5 years ago

Updated version of video using Android Studios found here: youtu.be/ToOX2OTCYAk

Guide/demonstration to switching between activities in an Android program.
Steps listed below in the description.

Link to previous demo for creating a button:

1. Create the layout
- Create a new layout file under res/layout
- Named: second.xml
- Make it show something new (text field, icon...)

2. Create new Java class
- Create a new Java class: SecondScreen
- Override the onCreate():
protected void onCreate(Bundle savedInstanceState) {

3. Add activity to manifest
- Application tab, add new "Application Nodes"
- Add, "Create a new element at the TOP LEVEL", Activity
- Set name: Select java class from above.
- Set Label (if desired)

4. Java code to switch activities
startActivity(new Intent( [Current Activity's 'this'], [New Activity's Java].class));

startActivity(new Intent(InClassDemoApp1.this, SecondScreen.class));

- Suggestion: Put launch code inside button callback:

Button daClicker = (Button) findViewById(R.id.button1);
new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SecondScreen.class));

5. Activity Stack
- Loading an Activity are pushed on the Activity *Stack*
- Activity's finish() method pops it
Returns to previous activity on stack.
- Must use correctly!

- Can move on and kill current activity:

6. 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?
Customize Your Hybrid Embed Video Player!

6-digit hexadecimal color code without # symbol.


Report video function is under development.


Loading related videos...