I have a process, getNextBook, that takes maybe 5 or 20 seconds,
depending on the size of the next book. It works OK but I need to
inform the user that "I'm working, just wait" so they will not tell
the App to do something else before the getNextBook process finishes.
(the code for "something else" is not included for the sake of
simplicity). I have included the display of a ProgressDialog so the
user can see when it is working and when it finishes. I have
experimented until I got it to work but there is something I do not
understand. The code is abbreviated for the sake of simplicity and it
does work even if I have created some error when I abbreviated.)

I utilize AsyncTask to make another thread so I will not block the
main thread. I want to call the ProgressDialog directly from the
AsyncTask getNextBook_T, but I cannot get it to work. Is there a way
to implement the ProgressDialog directly from getNextBook_T? Or is it
OK (or necessary) to do it indirectly like the code shows?

Thanks for your help

<code>
package very.long.name.App01;

import android.app.Activity;
import android.app.ProgressDialog;

public class App01 extends Activity {
        private ProgressDialog pd;

        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        String strTemp;
        switch (item.getItemId()) {
        case R.id.mnuCkSrv:
                        // bla, bla, bla....
                return true;
        case R.id.mnuNextBook:
                        pd = ProgressDialog.show(this, "", "Downloading next 
book...",
true);
                new getNextBook_T().execute();
                return true;
        default:
                return super.onOptionsItemSelected(item);
        }
    }

        private class getNextBook_T extends AsyncTask<Void, Void, Integer> {
                protected Integer doInBackground(Void... arg0 ) {
                        return getNextBook();
                }
                protected void onPostExecute(Integer result) {
                pdDismisser();
                setDisplay("");
                }
        }

        public Integer getNextBook(){
        // bla, bla, bla....
        }

        public void pdDismisser(){
                pd.dismiss();
        }

}

</code>

-- 
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