¿Cómo pasar a otra actividad en unos segundos?

I have a splash screen. I just want it to wait for 1 or 2 sec and then move on to the next activity just then once. I understand there are many ways including handler classes and java.util.timer implementation. But which is the easiest and most light way to do just this. Thanx in advance.

preguntado el 28 de agosto de 12 a las 14:08

i am not doing any animations or repeated actions for that matter. Thats why i asked for a much simpler solution. Just to go to the next screen after 2 sec. -

2 Respuestas

Use below Code for that.

Splash_Screen_Activity.java

public class Splash_Screen_Activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                // TODO: Your application init goes here.
                Intent mInHome = new Intent(Splash_Screen_Activity.this, InvoiceASAPTabActivity.class);
                Splash_Screen_Activity.this.startActivity(mInHome);
                Splash_Screen_Activity.this.finish();
            }
        }, 3000);
    }
}

Respondido 28 ago 12, 14:08

Thats what i was talking about. Worked like a charm. Thanx a lot!! - Abhinav

Here is an example, which includes fade effect.

res/transition/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="2000" />

res/transition/fade_out.xml

<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="1.0"
    android:toAlpha="0.0"
    android:duration="2000" />

MainActivity.class

public class MainActivity extends AppCompatActivity {

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

        final android.os.Handler handler = new android.os.Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(intent);
                overridePendingTransition(R.transition.fade_in,R.transition.fade_out);
            }
        }, 3000);
    }

}

For a complete app example (with more features)verificar aquí.

respondido 12 nov., 17:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.