Android: data loading and activity notification? A bad approach is also documented!

I just tried a silly approach and it crashed my application ... Basically I have an activity that has three tabs (containing three activities). Each tab gets its input from an xml file downloaded from the web. Everything is fine, but when I launch my application, it loads the xml file and there it "waits" for the time to do it.

I managed to get around this by adding a splash screen. It looks nice, but the problem is that when I click on the second tab, it should still get the list from the net, so now it looks ugly ... It waits before displaying the list. So, I made an AsyncTask design that just loads the xml file. In my main activity, I start two tasks initially and send the URL and Intent as parameters. And inside the acitivities that start inside the tabs, I use wait (). Inside the AsyncTask, after the download completes, I notify the intent with the notify () function. It crashed! Of course I didn't expect it to work, but just wanted to give it a try :) Wrote it so I can either get some feedback on why it failed, or prevent others from wasting their time on it ...

Now I am sure that many people are faced with the problem of "waiting" in tabs. How can I solve this? I am thinking about darkening the screen and then displaying a series of toasts, or displaying a progress bar inside the tabs, or pre-extracting the xml files ... I have no clue on how they can be achieved ... Any thoughts?

+2


source to share


2 answers


Credit: Check. Thank!

Problem: Displays a progress bar when the application is busy doing some work.

an approach:



public class Approach extends ListActivity {

    ProgressDialog myProgressDialog = null; 
    ListView myList = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        myList = getListView();

        myProgressDialog = ProgressDialog.show(getParent(),       
                "Please wait...", "Doing extreme calculations...", true); 
        //Do some calculations
            myProgressDialog.dismiss();

    }
}

      

There are several issues (like updating some UI elements). You might want to create another thread to do your calculations if needed.

Also, if you're interested, you might be interested in Matt's approach: android-showing-indeterminate-progress-bar-in-tabhost-activity

+2


source


ProgressDialog

...



Or make tabs android:visibility="gone"

until the data is ready, then do it visible

. In between, show some kind of loading graphics (perhaps with help RotateAnimation

).

+1


source







All Articles