Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:13:24+00:00 2026-06-09T07:13:24+00:00

I have a Tab Activity and 5 child activities. The Tab Activity is the

  • 0

I have a Tab Activity and 5 child activities.
The Tab Activity is the launcher activtiy.

When Activity 1 is started using tabHost.setCurrentTabByTag(CommonParams.HOME_TAG);, the phone’s back-button-press, fires the OnBackPressed of Actvitiy 1.

But when i start Activity 1 and then navigate to Activity 2 by clicking on the 2nd Tab, and then come back to Activity 1 by clicking on 1st tab, then the phone’s back-button-press does not fire the OnBackPressed(). It makes the app to exit.

I load the activities on tab press by the following code.

        intent = new Intent().setClass(this, Activity1.class);
        spec = tabHost
                .newTabSpec(CommonParams.HOME_TAG)
                .setIndicator("Home",
                        res.getDrawable(R.drawable.ic_tab_home))
                .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Activity2.class);
        spec = tabHost
                .newTabSpec(CommonParams.PAGE2_TAG)
                .setIndicator("Page2",
                        res.getDrawable(R.drawable.ic_tab_page2))
                .setContent(intent);
        tabHost.addTab(spec);

So when navigate from Home to Page2 and then back to Home using the tabs, Activity 1 is not started fresh. It is resumed. I suppose, OnBackPressed() is not getting fired on resumed activites.

Is it something like the activity lost its focus? If so how to avoid the activity losing focus, or how to give focus to the activity OnResume()?

Could someone help me to find why the OnBackPressed is not firing and how to make it work.

Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:13:26+00:00Added an answer on June 9, 2026 at 7:13 am

    what you are describing is the normal / default behavior of android. it’s exactly how it designed to work. if you’d like it to work different – you’ll need to implement it yourself with overriding the onBackPressed() callback of the main tab activity.

    anyway – for the behavior you’d like to achieve – I’m recommending you not to use tabs and TabActivity, but Fragments and FragmentManager. fragments have the built in mechanism handling back button requests in the why you need, and android recommends using it anyway. that’s why the TabActivity deprecated long time ago, since Honeycomb, and the competability back provided for Froyo and Gingerbread which adding the android fragments oriented API.

    this is what google wrote in the documentation of TabActivity:

    New applications should use Fragments instead of this class; to continue to run on older devices, you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT

    google don’t want that theTabActivity would be use anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tab setup as an Activity extension using API8 max. In this
I have a Tabhost which is my main activity. When a tab is clicked
I have a tabhost with two tabs. Each tab has his own activity. My
My application is Tab using ActivityGroup.I have done title of each activity using getParent().getParent().setTitle(New
I have a TabHost with a ListView inside a tab. When the activity starts,
I need some help :) I have a tab activity with four sub activities.
I have a TabHost with two child activities in it (in two tabs). I
I have tab activities (tab1, tab2). When button1 is pressed in tab1 activity it
My main activity is a TabActivity. I have some activities presented by the tab
I have implemented 3 Tabs in my applications using TabHost and TabActivity. Each Tab

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.