Alex
Alex

Reputation: 847

Back button edit action

I have a splash screen and if I press the back button while the splash activity is running this activity is closed but the next activity after the splash (after 2 seconds) will be open. I would like to set the back button to close the splash activity but to open immediately the next activity or to close the whole application.

Upvotes: 0

Views: 107

Answers (1)

Finn Larsen
Finn Larsen

Reputation: 2199

You need to override the back-button with this:

    @Override
    public void onBackPressed(){
       Intent i1 = new Intent(getApplicationContext(), NextActivity.class);
       startActivity(i1);
    return; 

This will take you to the next Activity when you pres the button. If you want to close the app try this:

        @Override
        public void onBackPressed(){
            moveTaskToBack(true);
        return;

Upvotes: 2

Related Questions