Alex Rivera | Logout

How to call another activity after certain time limit

Asked 2011-03-30T11:31:59.937
9

How to give time limit for calling one activity to another activity. I want to call another activity (Ex calling A class to B class) by given some time limit. I used alarmManager, but it is not possible for my application also i used threading, whenever i give Thread.sleep it will not perform action till the sleep getting end. I am not sure how to do this process. can anyone give a idea of giving time limit to calling a class.

Edit
Report

1 Answer

9

Here is a simply solution. this could be used for example for showing a splash activity for 1 second then going into the main app:

public class Splash extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);

            int secondsDelayed = 1;
            new Handler().postDelayed(new Runnable() {
                    public void run() {
                            startActivity(new Intent(Splash.this, ActivityB.class));
                            finish();
                    }
            }, secondsDelayed * 1000);
    }
}
answered 2011-03-30T13:16:15.413

Your Answer