oli
oli

Reputation: 63

How can I close activity without showing splash screen again?

I am making a splash screen and need help closing this activity so if a user presses the 'BACK' button they go back to the home screen, NOT the splash screen...

package com.Sosotech;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Splashscrn extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscrn);

        Handler x = new Handler();
        x.postDelayed(new SplashHandler(), 5000);

    }

 class SplashHandler implements Runnable {
     public void run() {
         startActivity(new Intent(getApplication(), Main.class));



     }
 }

}

PS: I just want to know if it is possible to make the splash screen come up every time the app is resumed. I will not be implementing this, I just wondered how it would be done.

Upvotes: 0

Views: 2096

Answers (2)

Austin Hanson
Austin Hanson

Reputation: 22040

To close the activity:

Splashscrn.this.finish();

For your PS
Set the activity as your main, launching activity and set clearTaskOnLaunch to true in the manifest.

Upvotes: 1

Vineet Shukla
Vineet Shukla

Reputation: 24031

use finish() as:

startActivity(new Intent(getApplicationContext(), Main.class));

finish();

Upvotes: 1

Related Questions