3

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.

2
  • How about this one? stackoverflow.com/questions/11455455/…
    – sdabet
    Aug 28, 2012 at 13:30
  • 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.
    – Abhinav
    Aug 28, 2012 at 13:52

2 Answers 2

15

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);
    }
}
1
  • 1
    Thats what i was talking about. Worked like a charm. Thanx a lot!!
    – Abhinav
    Aug 28, 2012 at 15:40
0

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), check here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.