ViewStub inflate en segundo Plano

230 views
Skip to first unread message

Francisco Lopez Montoya

unread,
Jun 18, 2012, 8:06:28 AM6/18/12
to desarrollad...@googlegroups.com
Hola a todos.

Tengo un problema que no logro solucionar, a ver si me podeis echar una
mano.

Tengo una activity que es una agenda en la que tengo un calendarview.
Este view tarda muchisimo en cargarse, unos 4 segundos, por lo que
quiero cargar el resto de la actividad y mostrar un progressbar hasta
cargarse el calendarview. He utilizado Un ViewStub para inflar el
calendarview y funciona bien pero el problema surge cuando quiero hacer
esta operaci�n en segundo plano, lo he intentado con un thread y un
Async y la excepcion es la misma. (Can't create handler inside thread
that has not called Looper.prepare()).
A ver si podeis ayudarme por que no puedo dejar una actividad que tarde
4 segundos en aparecer.
Gracias a todos.

@Override
public void onResume(){
super.onResume();
new Hilo().execute();
}

private class Hilo extends AsyncTask<Void, Void, Void>{
private ProgressBar pb;

@Override
protected Void doInBackground(Void...params) {
pb=(ProgressBar) findViewById(R.id.progressBar);
final ViewStub vs=(ViewStub) findViewById(R.id.calendarioView);
pb.setVisibility(View.VISIBLE)
vs.inflate();
return null;

}

protected void onPostExecute(){
calendario=(CalendarView)
findViewById(R.id.calendarioInflated);
pb.setVisibility(View.INVISIBLE);
}


}

06-18 13:55:24.300: E/AndroidRuntime(836): FATAL EXCEPTION: AsyncTask #1
06-18 13:55:24.300: E/AndroidRuntime(836): java.lang.RuntimeException:
An error occured while executing doInBackground()
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.os.AsyncTask$3.done(AsyncTask.java:266)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.lang.Thread.run(Thread.java:1020)
06-18 13:55:24.300: E/AndroidRuntime(836): Caused by:
android.view.InflateException: Binary XML file line #2: Error inflating
class android.widget.CalendarView
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.LayoutInflater.createView(LayoutInflater.java:596)
06-18 13:55:24.300: E/AndroidRuntime(836): at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.LayoutInflater.inflate(LayoutInflater.java:457)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.LayoutInflater.inflate(LayoutInflater.java:391)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.ViewStub.inflate(ViewStub.java:232)
06-18 13:55:24.300: E/AndroidRuntime(836): at
es.montoya.clinic.activities.AgendaActivity$Hilo.doInBackground(AgendaActivity.java:117)
06-18 13:55:24.300: E/AndroidRuntime(836): at
es.montoya.clinic.activities.AgendaActivity$Hilo.doInBackground(AgendaActivity.java:1)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.os.AsyncTask$2.call(AsyncTask.java:252)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-18 13:55:24.300: E/AndroidRuntime(836): ... 4 more
06-18 13:55:24.300: E/AndroidRuntime(836): Caused by:
java.lang.reflect.InvocationTargetException
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.lang.reflect.Constructor.constructNative(Native Method)
06-18 13:55:24.300: E/AndroidRuntime(836): at
java.lang.reflect.Constructor.newInstance(Constructor.java:416)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.LayoutInflater.createView(LayoutInflater.java:576)
06-18 13:55:24.300: E/AndroidRuntime(836): ... 14 more
06-18 13:55:24.300: E/AndroidRuntime(836): Caused by:
java.lang.RuntimeException: Can't create handler inside thread that has
not called Looper.prepare()
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.os.Handler.<init>(Handler.java:121)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.GestureDetector$GestureHandler.<init>(GestureDetector.java:250)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.GestureDetector.<init>(GestureDetector.java:370)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.GestureDetector.<init>(GestureDetector.java:347)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.view.GestureDetector.<init>(GestureDetector.java:331)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.widget.CalendarView$WeeksAdapter.<init>(CalendarView.java:976)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.widget.CalendarView.setUpAdapter(CalendarView.java:640)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.widget.CalendarView.<init>(CalendarView.java:398)
06-18 13:55:24.300: E/AndroidRuntime(836): at
android.widget.CalendarView.<init>(CalendarView.java:327)
06-18 13:55:24.300: E/AndroidRuntime(836): ... 17 more

Felipe Ovalle

unread,
Jun 18, 2012, 10:35:41 AM6/18/12
to desarrollad...@googlegroups.com
Deberias poner antes del llamado al thread  Looper.prepare()  y al final  Looper.loop();

mira este link:

El 18 de junio de 2012 09:06, Francisco Lopez Montoya <f.lopez...@gmail.com> escribió:
Hola a todos.

Tengo un problema que no logro solucionar, a ver si me podeis echar una mano.

Tengo una activity que es una agenda en la que tengo un calendarview. Este view tarda muchisimo en cargarse, unos 4 segundos, por lo que quiero cargar el resto de la actividad y mostrar un progressbar hasta cargarse el calendarview. He utilizado Un ViewStub para inflar el calendarview y funciona bien pero el problema surge cuando quiero hacer esta operación en segundo plano, lo he intentado con un thread y un Async y la excepcion es la misma. (Can't create handler inside thread that has not called Looper.prepare()).


--
Has recibido este mensaje porque estás suscrito al grupo "desarrolladores-android" de Grupos de Google.
Para publicar una entrada en este grupo, envía un correo electrónico a desarrolladores-android@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a desarrolladores-android+unsub...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/desarrolladores-android?hl=es.




--
Ing. Felipe Tomás Ovalle / ftovalle
Desarrollo de Sistemas Java, Android, Php 
Tel. 341 155 052447 -
www.ftovalle.com.arMsn: ftov...@hotmail.comSkype: ftovalle
Reply all
Reply to author
Forward
0 new messages