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

  • Home
  • SEARCH
  • 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 8279311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:17:37+00:00 2026-06-08T09:17:37+00:00

I created TabActivity having two tabs with two activities. one is login tab another

  • 0

I created TabActivity having two tabs with two activities.
one is login tab another is welcome tab.

user should not go welcome tab unless login successfully.if he tries to select welcome tab he throws to login tab.i use tabHost.setcurrenttab(index).

But when i click direct welcome tab it works fine for first time. When i again click tab rapidly it opens welcome tab.

Here is my code:

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.product_list);
            SharedPreferences mPreference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            username = mPreference.getBoolean("valid", false);
            Toast.makeText(this, "In Create", Toast.LENGTH_SHORT).show();
           //login sucessful            
           tabActivity.switchTab(0);
     }

on onResume, i repeat the same code.

  • 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-08T09:17:39+00:00Added an answer on June 8, 2026 at 9:17 am

    Try this in your TabActivity. This is to prevent user to switch tab if he is not logged in.(I have no time to check it now,please let me know if any issue is there with the code):

    SharedPreferences mPreference;
    ....onCreate(){
    
        ...
    
        mPreference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        tabHost.setOnTabChangedListener(new OnTabChangeListener() {
    
        @Override
        public void onTabChanged(String arg0) {
    
                    username = mPreference.getBoolean("valid", false);
                    if(user is logged in){
                         tabHost.setcurrenttab(0);//welcome page
                    }
                    else{
                         tabHost.setcurrenttab(1);//login page
                    }
            }
        });
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created three tabs in TabActivity onCreate . How can I hide one
I have created an application having tab activity which in turn has 5 different
I have created TabActivity class in which i am creating four tabs for my
I've created a simple TabActivity which builds tabs at runtime reading some JSON data.
I have created a tab based app, in one of the tab, there is
Having some trouble passing values from one class to another. I basically have a
I have a TabActivity that has three tabs. The fist tab is the problem.
I have created tabs using intents.MainPage.java is my class that extends TabActivity and other
Have another issue here. Our app starts out with a tab activity. But, before
I've created a TabHost example with 1 tab which is running fine. I'm adding

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.