In this case, it sounds like the message queue doesn't get a chance to
display the activity before it starts working on the AsyncTask.
You'll probably want to delay starting the AsyncTask until just after
the activity finishes loading and displaying to the user. Implement
MessageQueue.IdleHandler, and try starting the AsyncTask in the
queueIdle() call:
public boolean queueIdle() {
new getDataTask().execute();
return false;
}
Then, in your onCreate(), add your idle listener to the message queue:
final MessageQueue messageQueue = Looper.myQueue();
messageQueue.addIdleHandler(this);
This approach is being used in Launcher to make sure we finish showing
the activity before we start loading widgets:
http://android.git.kernel.org/?p=platform/packages/apps/Launcher.git;a=blob;f=src/com/android/launcher/Launcher.java;hb=cupcake#l1995
j
On Mon, May 18, 2009 at 8:10 AM, AusR <[email protected]> wrote:
>
> Hi all,
>
> I have ListActivity to show a custom list. The adapter for this list
> is a complex layout only known for each row at runtime depending on
> data gathered in a previous activity.
>
> The question I have is simple. I know it takes 4-6 seconds to prepare
> the adapter for the rows that will be visible (first 10), however I
> would like to let the user know by means of the empty list
> functionality or otherwise.
>
> At present the ListActivity is launched via a button on a previous
> activity and when that button is clicked the new activity will not be
> loaded until the adapter is completed, and the user is stuck with the
> previous activity until this happens.
>
> Using the basic code below where ListingAdapter is my custom complex
> adapter how can I get the activity to show 'some' element, or even
> appear on screen before the adapter loads so I can display a 'loading'
> message to the user?
>
> Do I need to move the placement of setListAdapter?
>
> @Override
> public void onCreate(Bundle icicle) {
> super.onCreate(icicle);
>
> requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
> setContentView(R.layout.custom_grid);
>
> new getDataTask().execute();
> }
>
> private class getDataTask extends AsyncTask<String, Integer, Long> {
> protected Long doInBackground(String... params) {
> adapter = new ListingAdapter();
> //setListAdapter(adapter);
> return null;
> }
>
> protected void onPreExecute() {
> super.onPreExecute();
> setProgressBarIndeterminateVisibility(true);
> }
>
> protected void onPostExecute(Long result) {
> setListAdapter(adapter);
> setProgressBarIndeterminateVisibility(false);
> }
> }
>
>
> >
>
--
Jeff Sharkey
[email protected]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---