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
it?
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
wrong.

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
created.


// tab host:
public class TabHostTest extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  TabHost th = getTabHost();
   th.addTab(th.newTabSpec("mytab")
   .setIndicator("I'm a tab")
   .setContent(new Intent(this,
   cc.thtest.TabOne.class)
   .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    }}

//tab:
public class TabOne extends Activity {
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
  setContentView(R.layout.tab_one_content);
   TextView tv = (TextView) findViewById(R.id.txt);
    tv.setText( "Cur time Is : " + System.currentTimeMillis() );
  }}

// xml:
 <LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
     <TextView android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="No data"/>
 </LinearLayout>


--~--~---------~--~----~------------~-------~--~----~



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.
So:
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?

Thanks.

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Help - adb cant' see running emulators, emulator can't connect to internet

Sorry for dredging up an old one, but I've been suffering the same problems 
and I think I've fixed it.

interface who may not necessarily be the right network. To fix:

open control panel\Network and internet and click on "view network status 
and tasks". Then click on "change adapter settings".

press alt then select "advanced" then "advanced settings".

On provider order tab, I swapped the "microsoft windows network" with " 
microsoft remote desktop session host server network provider" so the 
"microsoft windows network" was at top instead of second.

I'm guessing this meant the emulator was trying to use a remote desktop 
network to communicate through and obviously that ain't gonna work.

Hope this helps others.

-- 

2. Regarding Database

hi,

Am new to android please help me in my help query:

*"how to take data from edit text and store it in database*?"

Regards,
Yogendra G(9916168647)

-- 

3. Keyboard layout

4. Does Android native ActiveSync client support client certificates?

5. Need help regarding my ANDROID SELINUX project

6. AnDevCon March San Francisco

7. Android's Data Stealing Vulnerability