Thursday, September 9, 2010

RE: [android-developers] Layout being displayed too late

Thanks for the response. I tried switching to AsyncTask and have had great success but I am now stuck on what appears to be a minor point. Yet I can see my error. Attached is a snippet:

 

 

    private class LoadSchedules extends AsyncTask<Object, Object, Object>  {

           

            @Override

            protected void onPreExecute () {

                        mProgressText.setText("Let's begin");

                       

            }

 

            @Override

            protected Object doInBackground(Object... arg0) {

                        publishProgress("agencies");

                    Load_Table("agencies", "agency.txt",AgencyFlds, mAgencies);

 

                    publishProgress("calendar");

                    Load_Table("calendar","calendar.txt",CalendarFlds, mCalendar);

 

                    publishProgress("routes");

                    Load_Table("routes", "routes.txt", RouteFlds, mRoutes);

 

                        return true;

            }

 

                       

            @Override

            protected void onProgressUpdate(String... tablename){

                        mProgressText.setText("Loading " + tablename);

            }

 

            @Override

            protected void onPostExecute (Object b) {

                        mProgressText.setText("Game over");

                                                                       

            }

     }

________________________________________________________________________

 

The compiler keeps complaining that my  onProgressUpdate method must “Override or implement a supertype method”. When I remove the @Override, the compiler is happy. However when I run the app, I do not get the progress updates. I have tried various combinations of coding this method but with no success. I am sure it is something simple. Can someone please save me some time?

 

TIA


From: android-developers@googlegroups.com [mailto:android-developers@googlegroups.com] On Behalf Of TreKing
Sent: Wednesday, September 08, 2010 10:10 PM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] Layout being displayed too late

 

On Wed, Sep 8, 2010 at 8:12 PM, lloyd1949 <lloydmcfarlane@comcast.net> wrote:

Could someone please point out where I am going wrong?


You're executing long-running processes in the main thread (onCreate) which don't return control to the main (UI) thread to allow it to show your progress dialog until it's too late. Look into AsyncTask.

Also, the "mCtx = this;" is rather pointless. You're keeping a reference to yourself - which is exactly what "this" is.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment