6

I am creating an android application. I have a logo screen(Activity) and then my home screen(another activity). I want that when I start my application my logo screen should come and then automatically after 2 sec my home screen should appear. Can anyone please suggest to me what I should do?

rmtheis
  • 5,992
  • 12
  • 61
  • 78
Antrromet
  • 15,294
  • 10
  • 60
  • 75

3 Answers3

8

Please use this..

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

public class Logo extends Activity {
protected boolean _active = true;
protected int _splashTime = 2000;

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

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            finish();
            Intent i3 = new Intent(Logo.this, Home.class);
                startActivity(i3);
        }
    }, _splashTime);
}
}
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
Nikhil
  • 16,194
  • 20
  • 64
  • 81
  • Also for future readers, You should override the `onBackPressed()` otherwise if the user closes the app (by pressing the back button) in the splash screen then the next activity will still open because of the Handler running in the background. – Antrromet Jun 23 '15 at 06:52
1

You can use TimerTask.On TimerTask schedule a task after 2 minutes.And perform the task below

To use Timer Task see the link TimerTask

LogoScreen.this.startActivity(new Intent(LogoScreen.this,HomeScreen.class));

Community
  • 1
  • 1
Rasel
  • 15,499
  • 6
  • 40
  • 50
0

you can use CountDownTimer to open activity automatically after some time when CountDownTimer finish then in the onFinish() method you can write code to change activity.

Shay Kin
  • 2,539
  • 3
  • 15
  • 22