cómo mostrar un brindis después de 10 segundos desde el inicio de Asynctask

please suggest me how to execute something after 10 seconds from the start of AsyncTask. I have used AsyncTask for different purpose. But, now I want to update my UI after 10 seconds. Or to show a toast after specific time.

I actually want to perform some other task after 10 seconds, while the original task is running

please let me know how to do this.?

Gracias a todos.

preguntado el 31 de julio de 12 a las 13:07

4 Respuestas

just use any view instead of handler in onPreExecute method of your async task like:

    protected void onPreExecute() {
        view.postDelayed(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub

        }, 10000);

Respondido 31 Jul 12, 14:07

what should be the view in case I want to show the toast, after 10 seconds? - narendra singh

@NarendraDroidWorm you can use any view. or if you havent any you can create a handler. also runable will be run in main thread, so you can show toast without any problems - Alex Klimashevski

@ Alex Klimashevsky. Can you please suggest any link of this kind of logic? - amigo narendra

@nick as written below desarrollador.android.com/reference/android/os/… :) but just simpler - Alex Klimashevski

@AlexKlimashevsky. Thank you. - amigo narendra

You can use Android's CountdownTimer on onPreExecute of AsyncTask: http://developer.android.com/reference/android/os/CountDownTimer.html

And set countdowntimer to 10 secs (10000 ms). Its easy to use.

Respondido 31 Jul 12, 13:07

in your AsyncTasks onPreExecute function. - Atún Karakasoglu

Go for timer task. The TimerTask class represents a task to run at a specified time. The task may be run once or repeatedly. here is the link :- http://developer.android.com/reference/java/util/TimerTask.html

Respondido 31 Jul 12, 13:07

You can set up a Handler in your UI Thread and Toast with Handler.postDelayed(Runnable runnable, long delayMillis).

Respondido 31 Jul 12, 13:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.