Android Build an Interactive Story App The Rest of the Story Finishing an Activity

Kayondo Martin
Kayondo Martin
7,481 Points

How do I get to resume previous activity without knowing the previous activity details at all?

I can't find a way to resume.

LandingActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class LandingActivity extends AppCompatActivity {

    public Button relaunchButton;

    // Some previous code omitted for brevity

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_landing);

        // Some previous code omitted for brevity

        relaunchButton = (Button)findViewById(R.id.relaunchButton);
        relaunchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Add your code here!

            }
        });
    }
}

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey Kayondo!

You don't need to know anything about the previous Activity. You just need to finish up the current Activity and Android will automatically jump you back to the previous Activity. To finish the Activity you can use the 'finish' method:

// Add your code here!
finish();