views:

1149

answers:

2

I've searched and I know it seems some people frown upon using activities within tabs, but moving past that...how would I restart a tabbed activity while still keeping the tabs visible? I have an activity in a tab, I use the menu to create a new activity to update the tab's activity displayed info, when I return from the menu activity I want the new information to be displayed in the tab's activity. I am using startActivityForResult() from the menu choice, but when I return and try to restart the activity...it wipes out the tabs above(I guess as expected, but I want to re-launch the refreshed activity within the tab).

Creating the tabs:

  TabHost host = getTabHost();
  Intent home_intent = new Intent(constants.HOME_ACTION,
    null, this, homeTab.class);
  Intent inbox_intent = new Intent(constants.INBOX_ACTION,
    null, this, inboxTab.class);
  Intent stats_intent = new Intent(constants.STATS_ACTION, null,
    this, infoTab.class);

  host.addTab(host.newTabSpec(constants.HOME_TAG)
    .setIndicator(getText(R.string.home_label),
      getResources().getDrawable(R.drawable.icon))
    .setContent(home_intent));
  host.addTab(host.newTabSpec(constants.INBOX_TAG)
    .setIndicator(getText(R.string.inbox_label),
      getResources().getDrawable(R.drawable.icon))
    .setContent(inbox_intent));
  host.addTab(host.newTabSpec(constants.STATS_TAG)
    .setIndicator(getText(R.string.stats_label),
      getResources().getDrawable(R.drawable.icon)).setContent(
      stats_intent));

Return from the menu activity in the tab's activity(updating database info):

  public void onActivityResult(int requestCode, int resultCode, Intent data) {     
  super.onActivityResult(requestCode, resultCode, data); 
  switch(requestCode) { 
  case (constants.ACTIVITY_REQUEST_CODE_UPDATE_PROFILE) : { 
   if (resultCode == Activity.RESULT_OK) { 
    boolean profileUpdated = data.getBooleanExtra(constants.ACTIVITY_BUNDLE_UPDATE_PROFILE, false);
    Log.d(LOG_TAG, "activity returned with " + profileUpdated);
    // Check to see if we updated our profile to refresh the screen
    if(profileUpdated == true){
     // Refresh the screen with the new info
     homeTab.this.finish();
     this.startActivity(getIntent());
    }
   } 
   break; 
  } 
  } 
 }
A: 

some people frown upon using activities within tabs

Hi! I'm "some people"!

how would I restart a tabbed activity while still keeping the tabs visible?

You don't, AFAIK.

Of course, since you're the one who is finish()-ing and restarting the activity, you can easily stop that from happening by commenting out those two lines of code. Your problem isn't that you're losing the tabs -- it's that you're smashing your activity with a sledgehammer when there is probably a better way of doing whatever sort of "refresh" you are trying to achieve.

Of course, doing that sort of refresh would probably be easier if you had Views for your tabs instead of Activities, which is one of the reasons "some people frown upon using activities within tabs".

CommonsWare
Hah, hi "some people". I actually was specifically thinking of you when I wrote that since your posts are the ones I came across(thanks, by the way, for all the knowledge you share with everyone). So I commented on another answer that further explains what I'm trying to do. I am not that great with the terminology yet, but I believe I am using a view in the activity...I think:protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.hometab);TextView name = (TextView) findViewById(R.id.home_name); etc.Any way to refresh these objects?
D.
I think I have it. On the onActivityResult() return I can just update the Textview fields by just querying the database and updating the Textview by using .setText(). Simple...sorry I didn't see it.
D.
A: 

Yeah, I think it's safe to say that finishing and restarting yourself as an Activity within a tab is not a supported use case. Instead, when you know a "profile has been updated", is there a better finer grained way to refresh its state? E.g query a content provider to refresh the information represented in the activity? It all depends on what information is being represented in the Activity.

Karl R
The activity that displays the profile information pulls the info from a database. When a user decides to update the profile info, a new activity starts, the user makes the DB changes, then that activity ends and returns to the previous "tabbed activity" that now is displaying stale information. How would I display the updated info? Should I keep a global cursor and requery it when the updating task returns? Is there a built in way to refresh "textview" fields? Thanks for any input.
D.