Finishing AsyncTask in Android after a few seconds

Posted: March 20, 2015 in Android

Just like that , I needed to make a call to an AsynTask in Android, after reading differents threads in stackoverflow about the solutions I found mine doing this:

new GetAsyncTask(this).execute().get(10000,TimeUnit.MILLISECONDS);


This waits for 10 sec doing the request, if time is over just finishes and I catch an Exception to continue with the flow.
Seems that AsyncTask must be used only for Task that won’t consume too much time.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s