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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:11:45+00:00 2026-05-31T22:11:45+00:00

Currently my code loads a TabWidget with 4 tabs. The first tab points to

  • 0

Currently my code loads a TabWidget with 4 tabs. The first tab points to a disclaimer page which also takes in a username from a edittext box and stores it internally on the phone. I would like to have an if condition which checks to see if the username is stored on the phone and if it is then show the user a different “thank-you” page than the original disclaimer page. I believe my code isn’t working because it’s under the onCreate function and isn’t refreshing…

    public class TabWidgetActivity extends TabActivity {

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Reusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab


    // Create an Intent to launch an Activity for the tab (to be reused)

    String username = null;  
    String pulledUsername = getPreferences(MODE_PRIVATE).getString("username",username);

    // ******* MAIN PART I'M HAVING TROUBLE WITH ********************************

    if (pulledUsername != null){
    intent = new Intent().setClass(this, HomeActivity.class);
    }
    else {
    intent = new Intent().setClass(this, DisclaimerActivity.class);
    }

    // ^^^^^^^^^^^^^^^ MAIN PART I'M HAVING TROUBLE WITH ^^^^^^^^^^^^^^^^^^^^^^

    // Initialize a TabSpec for each tab and add it to the TabHost

    spec = tabHost.newTabSpec("home").setIndicator("Home",
                      res.getDrawable(R.drawable.ic_tab_home))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs

    intent = new Intent().setClass(this, ShowMapActivity.class);
    spec = tabHost.newTabSpec("map").setIndicator("Map",
                      res.getDrawable(R.drawable.ic_tab_map))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, SurveyActivity.class);
    spec = tabHost.newTabSpec("survey").setIndicator("Survey",
                      res.getDrawable(R.drawable.ic_tab_web))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, AnalysisActivity.class);
    spec = tabHost.newTabSpec("analysis").setIndicator("Analysis",
                      res.getDrawable(R.drawable.ic_tab_analysis))
                  .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(2);
     }
    }
  • 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-31T22:11:47+00:00Added an answer on May 31, 2026 at 10:11 pm

    Can you be a bit more clear about what “isn’t working”?

    Are you setting the username in the preferences within this Activity? If not then you should be using getSharedPreferences() as preferences are stored on a per activity basis.

    when writing the username in the Disclaimer Activity

      SharedPreferences settings = getSharedPreferences("com.blah.application", MODE_PRIVATE);
      SharedPreferences.Editor editor = settings.edit();
      editor.putString("username", username); 
      // Commit the edit!
      editor.apply();
    

    When pulling the username in the other activity:

    pulledUsername = getSharedPreferences("com.blah.application", MODE_PRIVATE).getString("username",null)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a tabview with 3 tabs. 1 tab loads an ActivityGroup which
I currently have the following code that loads a UIWebView from another View. Now
I'm currently working on a script which extracts data from two sources where one
currently I have a web which loads excel spreadsheet data into SQL database. When
Currently I have a web service, which loads up any plugins located within its
I am currently loading a lightbox style popup that loads it's HTML from an
I have a simple page that loads a random image from an array and
I have a user input page which loads different forms with ajax depending on
I'm currently using the below code within a winform which is generated and compiled
I have some code which fetches an XML file from a URL and then

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.