Saturday, February 9, 2013

Android: Invoke a method after some delay



If you have a method which you want to call after some delay



        //Create a delay handler
        Handler delayHandler= new Handler();
        Runnable r=new Runnable()
        {
@Override
public void run() {

// Call this method after 1000 milliseconds
showCountryListViewIntent();
}
        
        };
        delayHandler.postDelayed(r, 1000);



    ///This method will be called after say 1000 milliseconds.
    //This will call the another Activity
    public void showCountryListViewIntent()
    {
    Intent countryListIntent=new Intent(this,CountryListActivity.class);
    startActivity(countryListIntent);
    }


You can find the sample code DOWNLOADABLE HERE.





No comments:

Post a Comment