0

Hello I want to make my intent happen after 1second, its purpose is a flash screen at the start of my application.

//Creates a new screen for the painter to select what route he wants to go down. A flash screen.


 public void nScreen(View view)
    {
        Intent intent = new Intent(MainActivity.this, Main22Activity.class);
        startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Kripzy
  • 39
  • 1
  • 7

3 Answers3

0

You can use this code

private final int SPLASH_DISPLAY_LENGTH = 1000;


@Override
protected void onResume() {
    super.onResume();

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            MainActivity.this.finish();
            Intent mainIntent = new Intent(MainActivity.this, Main22Activity.class);
            startActivity(mainIntent);
        }
    }, SPLASH_DISPLAY_LENGTH);
}
Inducesmile
  • 2,475
  • 1
  • 17
  • 19
0

To achieve that you can use a Handler, for example

new Handler().postDelayed(new Runnable(){
    public void run() {
       //CODE HERE
    }
}, 1000); //1000 mills is one second
Eury Pérez Beltré
  • 2,017
  • 20
  • 28
0

Try this

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

     Thread thread = new Thread() {
                    public void run() {

                        try {
                            // Thread will sleep for 1 seconds
                            sleep(1000);
                            // After 1 seconds redirect to another intent
                            Intent intent = new Intent(MainActivity.this, Main22Activity.class);
                            startActivity(intent);
                            //Remove activity
                            finish();

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                };

                // start thread
                thread.start();
}

Hope this helps you

saeed
  • 1,935
  • 1
  • 18
  • 33