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 3964238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:18:35+00:00 2026-05-20T03:18:35+00:00

Friend’s, I implemented tabhost in my application,i have three tabs defined in my activity

  • 0

Friend’s,
I implemented tabhost in my application,i have three tabs defined in my activity tab1,tab2,tab3…here i have a problem to navigate from tab3 to tab1 at onkey back pressed event ,how can i reach the tab1 from tab3 and tab2,i tried up using overided keyback pressed,but it some times it’s not responding to navigate.without overriding onkey back pressed it simply exits from application.

Here my code

tabHost= getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1").setContent(
                new Intent(this, DealCities.class)).setIndicator(prepareTabView("Deals",R.drawable.test)));

        tabHost.addTab(tabHost.newTabSpec("tab2").setContent(new Intent(this, DbServerActivity.class))
                        .setIndicator(prepareTabView("My QuadDeals",R.drawable.mydeal)));

        tabHost.addTab(tabHost.newTabSpec("tab3").setContent(new Intent(this, Account.class))
                .setIndicator(prepareTabView("My Account",R.drawable.img_myaccount)));

here the tabhost defined in one class and the tabhost object being static one,

here the code from my tab2 back pressed event has follows,

 @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

            try {               
//              userdealList.setVisibility(View.GONE);              
//              logalertTable.setVisibility(View.GONE);
//              dealType.setVisibility(View.GONE);
//              mydealBack=1;
//              QuadMain.tabHost.setCurrentTab(0);  
                Intent i = new Intent();
                i.setClass(DbServerActivity.this, QuadMain.class);
                i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);

            } catch (Exception e) {

            }
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

it works fine sometimes only and sometimes it’s not working..

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-05-20T03:18:36+00:00Added an answer on May 20, 2026 at 3:18 am

    Check out this manual http://knightswhocode.com/wordpress/?p=46 – teaches how to use TabHost. Unfortunately by default onkeyBackPressed event you just go to the previous activity and as you have one main tabhost activity it just quits. I suggest you overriding the back key pressed and use the following method:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            YourParentActivity parentActivity;
            parentActivity = (YourParentActivity) this.getParent();
            parentActivity.switchTab(indexTabToSwitchTo);
            return true;
        }
        return super.onKeyDown(keyCode, event); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Friend of mine has a problem :). There is an application written in Visual
friend's, i have an task to set horizontal swipe tabs below the header,how can
friend's I have a task to place the horizontal scroll or swipe menu tabs
friend's I have configured Flurry Analytics in my application,it points the users in the
Friend's I'm working upon searching in maps, here i have string in my array,when
A friend of mine is now building a web application with J2EE and Struts,
Friend's, I have an single image in which it set has screen home page
Friend's I have a task to parse thumbnail images and to set it on
My friend found a problem in my script, it gives acces to root files.
friend's I need help on running an application in 3G,the application works well in

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.