views:

1250

answers:

3

Hi, I'm having some difficulties getting the TabActivity to work. Here's the implementation of the class:

public class Profile extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final TabHost tabHost = getTabHost();


    if (tabHost.isEnabled()) {
     Log.e("profile", "enabled");
    }


    tabHost.addTab(tabHost.newTabSpec(getString(R.string.friendReqs))
            .setIndicator("requests")
            .setContent(new Intent(this, FriendRequests.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

    tabHost.addTab(tabHost.newTabSpec(getString(R.string.friends))
            .setIndicator("photo list")
            .setContent(new Intent(this, Settings.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    Log.e("profile", "add tabs");
    tabHost.invalidate();

}
}

The problem is that I call this class from my main activity (which is a MapActivity if it matters) and when I do the TabActivity doesn't show. It registers the click on the option menu and it even starts the intent but the screen doesn't change..it just stays on the main activity and i see in the logs that the main activity gets resumed. I call it like this:

Intent p = new Intent(this,Profile.class);
   p.putExtra(DBAdapter.KEY_USERID,userid);
   startActivity(p);

Like I said...there are no errors (the classes called from the tabs exist of course), just no actions. I put some log commands into the onCreate function in the tabactivity (as you see) and they all get written into the log...I have no idea what I'm doing wrong here. Any help?

A: 

I don't see setContentView() in your Activity, which you need.

synic
For a TabActivity you don't need.
Pentium10
Exactly...extending TabActivity should provide its own layout
Bostjan
A: 

Remove

tabHost.invalidate();

Also you can drop

Intent.FLAG_ACTIVITY_CLEAR_TOP

I don't see any purpose of this, as you need to see the activity anyway when you click on tabs.

Pentium10
Sadly that doesn't help either. I had it without the invalidate method at the start. I just put it there if it would help any...
Bostjan
Is there something wrong with the way I call TabActivity?
Bostjan
I have created a same OnCreate for my TabActivity today, it just looks the same except invalidate and I have no flags. And it worked.
Pentium10
Clearing the flag didn't work either. I set the flag since I wanted the activity to recreate each time I click on a tab (no storing history for back buttons)
Bostjan
Well if didn't work either, you have to look if a sample project runs fine for you. Check the <<Android install dir>>/platforms/.../samples/ApiDemo folder or create a new sample project from it. There are 3 examples for TabActivities
Pentium10
I know...I basically copied the APIDemos example and it wouldn't work. That's why I thought there was something wrong with the way it was called.
Bostjan
Yep...the samples work OK.
Bostjan
I am out of ideas. (maybe one last idea, double check if you added your tabactivity to manifest file)
Pentium10
Did that as well :) Thanks for the help though. I'll be sure to post back what the problem was when I sort it out.
Bostjan
Hm...interesting. If I set the first tab to a view instead of an intent it shows the tabs...i can also select the 2nd tab. Do you think it could be because the called intent in the 1st tab doesn't get a chance to load before it should be shown? Any way I can influence that?
Bostjan
Got it. The problem was the Activity being called in the 1st tab. It closed if there was no data passed to it (bundle). Thanks again for the help.
Bostjan
post this as a new answer (you answer your question) then in a few days StackOverflow will let you choose that as accepted answer.
Pentium10
+1  A: 

After some tries...

I set the first tab to a view instead of an intent and it showed the tabs...i could also select the 2nd tab.

Got it. The problem was the Activity being called in the 1st tab. It closed if there was no data passed to it (bundle). Thanks again for the help.

Bostjan