Ji Ya Ji Ya - 1 year ago 59
Android Question

Blank page in FragmentTabHost with AsyncTask

I'm new to Android and developing a FragmentTabHost page with 3 tabs. In the activity class, call an AsyncTask class to fetch data and put into Shared Preferences, then have the following code to add tabs. In each tab fragment class, get saved shared preferences data and display on page.

mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

AFragment.class, null);
BFragment.class, null);
CFragment.class, null);

The problem is that the first shown tab page is blank. Because it gets created before the async task has finished. Therefore, the information in the tab is shown only after changing tabs and reselecting it again. Any good solutions?

Much appreciated!

Answer Source

I found a workable solution. Call the async task in AFragment, put data in shared preference, then update UI. Another two fragments will read data from shared preferences directly.