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

Reply via email to