Hi,

I have the following AsynchTask class but, it fails to execute the
onProgressUpdate method when doInBackground is running. That is to say
the Log.v(LogName.onProgressUpdate, LogName.onProgressUpdate) never
occurs in LogCat. There are two calls to publishProgress. The first is
after the authentication text view is copied to the instance variable
and second in the update thread.

Can anyone offer insight?

public class AuthenticateTask extends AsyncTask<Dialog, Void, Boolean>
{

        private int num_dots;
        private boolean firstRun;
        private String textToUpdate;
        TextView textViewAuthenticating;
        Dialog dialog;

        private class LogName
        {
                public static final String className = "AuthenticateTask";
                public static final String onPreExecute = className + 
".onPreExecute():";
                public static final String doInBackground = className +
".doInBackground(Dialog...):";
                public static final String onProgressUpdate = className +
".onProgressUpdate():";
                public static final String onPostExecute = className +
".onPostExecute(Boolean):";
        }

        protected void onPreExecute()
        {
                Log.v(LogName.onPreExecute, LogName.onPreExecute);
                num_dots = 0;
                firstRun = true;
        }

        @Override
        protected Boolean doInBackground(Dialog... params)
        {
                Log.v(LogName.doInBackground, LogName.doInBackground);
                dialog = params[0];
                textViewAuthenticating = (TextView)
dialog.findViewById(R.id.TextViewAuthentication);
                publishProgress();
                Log.v(LogName.doInBackground, LogName.doInBackground + "dialog: 
" + dialog);

                Thread updaterThread = new Thread(new Runnable()
                {

                        public void run()
                        {
                                // TODO Auto-generated method stub
                                try
                                {
                                        Thread.sleep(250);
                                }
                                catch (InterruptedException e)
                                {
                                }
                                finally
                                {
                                        AuthenticateTask.this.publishProgress();
                                }
                        }

                });

                updaterThread.start();
                if (Authenticate())
                {
                        return true;
                }
                return false;
        }

        protected void onProgressUpdate()
        {
                Log.v(LogName.onProgressUpdate, LogName.onProgressUpdate);
                String tmpString;
                dialog.setContentView(R.layout.connnection_progess_dialog);

                if (firstRun)
                {
                        Log.v(LogName.onProgressUpdate, 
LogName.onProgressUpdate + "First Run");
                        textToUpdate = 
textViewAuthenticating.getText().toString();
                        Log.v(LogName.onProgressUpdate, 
LogName.onProgressUpdate +
"textToUpdate = " + textToUpdate);
                        firstRun = false;
                }
                if (num_dots++ == 5)
                {
                        num_dots = 0;
                }
                tmpString = textToUpdate;
                for (int i = 0; i < num_dots; i++)
                {
                        tmpString += " .";
                }
                Log.v(LogName.onProgressUpdate, LogName.onProgressUpdate +
"tmpString = " + tmpString);
                textViewAuthenticating.setText(tmpString);
        }
        protected void onPostExecute(Boolean result)
        {
                Log.v(LogName.onPostExecute, LogName.onPostExecute);
                String authentication_finished =
dialog.getContext().getResources().getString(R.string.authentication_finished);
                Log.v(LogName.onPostExecute, LogName.onPostExecute + 
authentication_finished);
                textViewAuthenticating.setText(authentication_finished);
                
textViewAuthenticating.setCompoundDrawables(dialog.getContext().getResources().getDrawable(R.drawable.checkmark),
null, null, null);
                firstRun = true;
        }

}


Regards,
-jm

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

Reply via email to