1
votes

As the documentation says if that activity has set launchMode="singleTop" in the manifest, the intent will come in through the onNewIntent callback.

I have been unable to get this behavior when the activity was started by a TabHost. Instead of calling onNewIntent, the activity's onCreate method is called, resulting in a new instance of the activity on top of the activity stack.

This is my code for starting the intent:

// create the TabHost that will contain the Tabs
            tabHost = (TabHost)findViewById(android.R.id.tabhost);


            TabSpec tab1 = tabHost.newTabSpec("First Tab");
            TabSpec tab2 = tabHost.newTabSpec("Second Tab");
            TabSpec tab3 = tabHost.newTabSpec("Third tab");

           // Set the Tab name and Activity
           // that will be opened when particular Tab will be selected
            tab1.setIndicator("Tab1");
            Intent intent = new Intent(this, WhenLogin.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
                    Intent.FLAG_ACTIVITY_SINGLE_TOP);
            tab1.setContent(intent);

Has anyone else had this problem? If so, have they found a solution?

1
What do you mean by "started by a TabHost"?CommonsWare
I am using tabs. When I didn't use tabs all worked fine.user3421416
Perhaps you could consider pasting in your source code to explain what you mean by "started by a TabHost".CommonsWare
I edited my code, Thanks for replaying.user3421416

1 Answers

0
votes

TabActivity, and the general approach of putting activities in tabs, has been deprecated for over 3.5 years. Plenty of experts were warning developers away from it for a long time prior to that. Please use a modern tab solution, such as a ViewPager with a tabbed indicator, or FragmentTabHost, or even a plain TabHost using Views for tabs.

As the documentation says if that activity has set launchMode="singleTop" in the manifest, the intent will come in through the onNewIntent callback.

That is only for activities started via startActivity() (and maybe startActivityForResult(), though using that in combination with singleTop worries me).

Instead of calling onNewIntent, the activity's onCreate method is called, resulting in a new instance of the activity on top of the activity stack.

The "new instance of the activity" is not on the activity stack, because it is not used as a full-fledged activity. Instead, the UI is ripped out of the activity and put into your TabActivity as a tab.