I have this button that when clicked saves the details entered in my textfields to Google App Engine, right after the call to that onClickListener, i have an intent that starts a new activity, which displays the details I just entered. Here is the code for this:
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.userDetailsCaptureButton) {
new EndpointsTask().execute(getApplicationContext());
}
startActivity(userProfileDisplayIntent);
}
});
Now i want to be able to wait for a couple of seconds before making a call to startActivity
after new EnpointsTask().execute(getApplicationContext)
has been called. I read that using Thread.sleep
causes the UI to freeze and as such isn't best suited for this. What other options are there?
The solution is to use a handler with a runnable and use of the method 'postDelayed'. Example:
new Handler().postDelayed(new Runnable() {
public void run () {
// Do delayed stuff!
}
}, 5000L); //5 seconds delay
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With