TabHost launching Intent multiple times

by Brian » Tue, 28 Apr 2009 12:51:23 GMT

Sponsored Links
 I'm seeing a strange behavior with a TabHost that creates a tab as a
new Intent.  Is this just the way it is, and I'll have to work with
The tab intent is created twice, instead of once.  I'm on the
emulator, sdk 1.1.
The behavior to get this is:

Launch tab host app, and note the state (call it state A)
Hit Home
Launch tab host app again, and note the state (state B)
Hit back button
The app should exit, but instead, State A is displayed, which is
actually the first tab Intent created.

I think this flow only happens on the first launch, but I may be

I'm thinking I can fix my "displaying old state" issue by rendering
out of the database, but it doesn't change that it seems like two
intents are created, when only one should be.  My best case here is
that the user will think hitting the back button "didn't work" the
first time, and will hit it again...

Here's the "hello world" code to see this.  Launch it once, hit home,
launch it again, and note the milliseconds it's displaying.  Hit back
button.  Woh, it's still displaying the app, but the milliseconds have
changed.  It's actually displaying the tab the first time it was

// tab host:
public class TabHostTest extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
  TabHost th = getTabHost();
   .setIndicator("I'm a tab")
   .setContent(new Intent(this,

public class TabOne extends Activity {
public void onCreate(Bundle savedInstanceState) {
   TextView tv = (TextView) findViewById(;
    tv.setText( "Cur time Is : " + System.currentTimeMillis() );

// xml:
 <LinearLayout xmlns:android=" 
     <TextView android:id="@+id/txt"
android:text="No data"/>


TabHost launching Intent multiple times

by Brian » Tue, 28 Apr 2009 19:51:58 GMT

 I got the same behavior with the Tabs2 APIDemo source, which doesn't
use Intents, but rather a TabContentFactory.

Until the app gets an onDestroy, it seems to add new instances into
the call stack, instead of reactivating the current one.  After it
gets an onDestroy, future launches work fine.
1. Launch app, hit home, launch app, hit home, launch app, hit home,
launch app.
2. Now start hitting the back button.  For as many times as you
launched the app, hitting the back button will display an old app
instead of exiting.
3. Continue hitting back button until the app gets an onDestroy()
(should 4 times in the example above)
3. Repeat from 1. Notice the change of behavior.  At 2, a single back
button will exit the app

Is there some bit that needs to be flipped after a launch?  Is this
just an emulator thing?



Sponsored Links

Other Threads

1. Getting ADT installed in Eclipse requires plug-in org.eclipse.jdt

If you're using the version of Eclipse that was packaged with the Flex
Builder 3, then your version of Eclipse is probably too old.

You need v3.4 or greater to do Android development, and the Flex
Builder 3 package comes with Eclipse v3.3

Hope it helps...


2. Basic Flashlight

Hello, I'm new with Android and am trying to build a simple Flashlight
program.  I've built a basic layout with two buttons, ON and OFF.
There are two onClockListeners defined, one for each button.  Here's
an example of what the OnClickListener does for the ON button:

        final Button on_button = (Button) findViewById
        on_button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
          //    turn on the light
        });             //      end setOnClickListener

The OnClickListener for the OFF button is very similar, save that, for
example, the setContentView takes as a parameter

I've defined two .xml files, one for R.layout.on (all white), and one
for (all black).  The idea is that by clicking one of the
two buttons, the respective xml file determines what the user sees.

Before I dig too deep into this approach, is there a fundamentally
different way I should be thinking about this problem?  Again, I'm a
newbie, but eager to learn.



3. email preferences

4. Delayed actions

5. debug certificate expire. What to do?

6. RE : Possible in emulator? Querrying google map? Unlocking Anrdoid Example

7. Multi threading in android