There are two approaches to achieve this.
Whenever you start your other activity (for example, a search operation), before you set the activity of the search to the desired tab. You can achieve this by taking an instance of your TabActivity (i.e., Your activity that extends this class) and calling new Intent().setClass(TABACTIVITY_INSTANCE,ACTIVITY YOU_WANT_TO_SET_TO_THIS_TAB) . But make the various objects of intention be like a class of members. Do not do something like this (new Intent().setClass()) .
Declare objects without intent as there are no tabs that you hold, and then use the setClass method. (This will solve your problem with the tab disappearing)
Now, to take data from the server, I suggest you implement AsyncTask (a wonderful api is available on Android):
private class DownloadImageTask extends AsyncTask<String, Void, String> { AbousUsHandler aboutHandeler; @Override protected void onPreExecute() { mProgress.setMessage("Please wait"); mProgress.show(); super.onPreExecute(); } protected String doInBackground(String... urls) { /* Do you your background task ie getting data from server but don't do ui related things here as this method is called in Thread pool not on Android Ui thread.*/ return null; } protected void onPostExecute(String result) { try { mProgress.dismiss(); /* set Your List View Adapter here */ } } }
Do this from the user interface thread only by calling new DownloadImageTask().execute() .
First, preExecute will be called, and then doInBackground , and when you get the data from the server, onPostExecute will be called.
Hope this solves your problem.
source share