2

I need to refresh my Activity once i click my Tab activity back. Currently its just displaying the previous content. I need to refresh my activity, so new contents can be loaded once its back. Here is my Code for adding the TabActivity. Please help. Appreciate for all your feedback.

    private void setTabs()
{
    addTab("Home", R.drawable.tab_home, OptionsActivity.class);
    addTab("News", R.drawable.tab_search, JsonActivity.class);
    addTab("Scores", R.drawable.tab_home, scores.class);
    addTab("Video", R.drawable.tab_search, JsonActivity2.class);
    addTab("Follow Us", R.drawable.tab_home, SAXParserActivity.class);
    addTab("Socket", R.drawable.tab_search, socketAndroid.class);
}



private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);

}
dhiku
  • 1,818
  • 2
  • 22
  • 38

3 Answers3

6

Here is the Final Addition of Code...I added .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

Thank You All.

dhiku
  • 1,818
  • 2
  • 22
  • 38
  • Though I would add this: "If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent." - http://developer.android.com/reference/android/content/Intent.html – else Mar 24 '14 at 11:40
1

Add the Flag .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); to your Intent as dhiko mentioned above and it will call the concerned activity each time you select the tab.

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
0

What type of content are you trying to update? If you are using an array adapter you can call notifyDataSetChanged(). Or if you can reference the text fields through their id attribute you can modify them dynamically.

Joel
  • 4,732
  • 9
  • 39
  • 54
  • Thank you Joel. I just added the addFlags(Intent, FLAG_ACTIVITY_CLEAR_TOP) and it works Great. Here is my Code – dhiku Jun 19 '12 at 20:51