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
> a AsyncTask while 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 the AsyncTask, 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 my AsyncTask class:
>
> private class LoadDictionaryTask extends AsyncTask<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-documented-problems-with-asynctask/
>
> --
> 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