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 trialTatenda Goteka
2,046 Pointsbuilding interactive story
Challenge Task 1 of 2
On this last challenge, all you need to do is override the onBackPressed() method and display a message that Back was pressed. Start by overriding the method and calling the parent (super) method right away.
Important: In each task of this code challenge, the code you write should be added to the code from the previous task.
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);
}
}
import android.os.Bundle;
public class PodcastActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_podcast);
}
}
1 Answer
David Tran
Courses Plus Student 12,429 Pointsimport android.os.Bundle;
public class PodcastActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_podcast);
}
// first challenge
@Override
public void onBackPressed() {
super.onBackPressed();
// second challenge
Toast.makeText(this, "You pressed the back button!", Toast.LENGTH_SHORT).show();
}
}
Bruce Lino
694 PointsBruce Lino
694 Points@Override public void onBackPressed() { super.onBackPressed(); Toast.makeText(getApplicationContext(),"Back was Pressed",Toast.LENGTH_LONG).show();
}