Reputation: 752
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.
Upvotes: 3
Views: 11843
Reputation: 10015
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.
Upvotes: 0
Reputation: 22291
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);
}
}
Upvotes: 15