Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App The Rest of the Story Navigation

Last but not least, create and show a simple Toast message that says "You pressed the back button!". Set the time for

Last but not least, create and show a simple Toast message that says "You pressed the back button!". Set the time for display using Toast.LENGTH_SHORT.

stuck

PodcastActivity.java
import android.os.Bundle;

public class PodcastActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_podcast);
    }

  @Override
  public void onBackPressed () {
    super.onBackPressed (); 
   Toast.makeText(this,"You pressed back the button", Toast.LENGTH_SHORT);                          }


}
foxaice
foxaice
12,038 Points

You have an error in the message. Try to copy it from the task of the challenge

Christopher Janke
Christopher Janke
11,054 Points

"You pressed back the button" needs to be "You pressed back the button!" *! being added on. You might need to do Toast.LENGTH_SHORT).show(); if the "!" doesn't resolve the issue.

foxaice
foxaice
12,038 Points

Christopher Janke "You pressed back the button" needs to be "You pressed back the button!" *! being added on. You might need to do Toast.LENGTH_SHORT).show(); if the "!" doesn't resolve the issue.

and you too have an error in the message. Pay attention to the order of word in task's message

5 Answers

Toast.makeText(this,"You pressed the back button!", Toast.LENGTH_SHORT).show();

the back button! instead of back the button. also don't forget .show()

still no luck here is the full code

import android.os.Bundle public class PodcastActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_podcast);
}

@Override

public void onBackPressed () { super.onBackPressed (); Toast.makeText(this,"You pressed back the button!,Toast.LENGTH_SHORT).show(); } }

Christopher Janke
Christopher Janke
11,054 Points

Bahaha. Good thing you were paying closer attention than I was, I could only see the missing "!".

foxaice
foxaice
12,038 Points

sean tatenda jack

Last but not least, create and show a simple Toast message that says "You pressed the back button!". Set the time for display using Toast.LENGTH_SHORT.

stuck

You have an error in the message. Try to copy it from the task of the challenge

Christopher Janke
Christopher Janke
11,054 Points

replace You pressed back the button! with this "You pressed the back button!" you are missing your ending " and you have the words "the" and "back" in the wrong order

Thanks Janke, you made my day!!

Spoiler Alert:

import android.os.Bundle;
public class PodcastActivity extends AppCompatActivity {


   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_podcast);
}

@Override

   public void onBackPressed () {
   super.onBackPressed();
   Toast.makeText(this,"You pressed the back button!",Toast.LENGTH_SHORT).show();
        }
   }