I am doing Looper.prepare(); in doInBackground() because without that,
it seems that exceptions are not catched.
Without that, if I remember, the application simply crashes...

The last call on my UI thread is thread.execute() (during
onCreate()) , so it seems that no get() is called, even if I don't
know what this
function (get) should do.

I changed my code and instead of loading serialized objects, I build
the dictionary and create objects in the background thread.
And the progress bar is correctly filled when each Family object is
created.

For user it takes about the same time as unserialization (I have not
measured exactly), but the apk is about 850ko (due to big xml files)
contrary to 350ko with file containing serialized objects.

On 6 mar, 20:12, Romain Guy <[email protected]> wrote:
> Hi,
>
> Why are you doing Looper.prepare(); in doInBackground()? Also, what
> you are seeing would indeed happen if you are calling get() somewhere
> on the UI thread, or otherwise blocking the UI thread after calling
> execute() on your task.
>
>
>
>
>
> On Fri, Mar 5, 2010 at 1:29 AM, Nicolas H <[email protected]> wrote:
> > Hey guys,
>
> > At the beginning of my application, I load a serialized dictionary in
> > aAsyncTaskwhile the UI thread should print a progress bar showing
> > the loading progress.
> > At the execution, the dictionary is well loaded but, the progress bar
> > becomes full at the end of theAsyncTask, just before the
> > postExecute() function is executed (where the main UI is drawn). So
> > the user doesn't know about the loading progress since
> > the progress bar doesn't change before the end of the loading.
>
> > The code of myAsyncTaskclass:
>
> > private class LoadDictionaryTask extendsAsyncTask<Void, Integer,
> > Void> implements Serializable{
>
> >               �...@override
> >                protected void onPreExecute() {
> >                     bar =
> > (ProgressBar)findViewById(R.id.progressbar);
> >                     bar.setMax(12);
> >                     bar.setProgress(0);
> >                 }
>
> >               �...@override
> >                 protected Void doInBackground(Void... unused) {
> >                        Looper.prepare();
> >                         try{
> >                                 ObjectInputStream ois = new
> > ObjectInputStream(getResources().openRawResource(R.raw.my_dico));
> >                                Family family;
> >                                for(int i=1; i<13; i++){
> >                                        family = (Family) ois.readObject();
> >                                        dictionary.put(family.familyName, 
> > family);
> >                                        publishProgress(i);
> >                                }
> >                                ois.close();
> >                        }
> >                        catch(Exception e){
> >                                Log.e("ERROR","error e : "+e);
> >                        }
>
> >                        return null;
> >                 }
>
> >               �...@override
> >                 protected void onProgressUpdate(Integer... progress) {
> >                         bar.setProgress(progress[0]);
> >                 }
>
> >               �...@override
> >                 protected void onPostExecute(Void unused) {
> >                         drawUI();
> >                 }
> >        }
>
> > If anyone has an idea....
>
> > PS : I found this, explaining the same problem :
> >http://vkroz.wordpress.com/2010/02/25/programming-android-non-documen...
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support.  All such questions should be posted on
> public forums, where I and others can see and answer them

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to