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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:28:22+00:00 2026-06-09T02:28:22+00:00

I’m trying to work with Tabhost, I have 2 tabs, each one loads one

  • 0

I’m trying to work with Tabhost, I have 2 tabs, each one loads one Activity, each Activity has an aSync method to parse some data. If I do setCurrentTab(0) when creating the Tabmenu Activity everything works fine, but if I try to start the app on the second tab(setCurrentTab(1)) it tries to load the first tab, and does the aSync method of the first tab and crashes because some data is lacking for method to work, which wasn’t supposed to be called at all.

Here’s the TabMenu.Activity:

public class TabMenu extends TabActivity {

TabHost tabHost = null;


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    setResult(resultCode);
    this.finish();
}

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);
    Intent intentToGet = getIntent();
    tabHost = getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 
    TabHost.TabSpec spec2; 
    Intent intent2; 

    intent = new Intent().setClass(this, HoursActivity.class);
    intent.putExtra("student", intentToGet.getStringExtra("student"));
    intent.putExtra("pass", intentToGet.getStringExtra("pass"));
    intent.putExtra("un", intentToGet.getStringExtra("un"));

    spec = tabHost
            .newTabSpec("hours")
            .setIndicator("Hours")
            .setContent(intent);
    tabHost.addTab(spec);

            intent2 = new Intent().setClass(this, NotesActivity.class);
    intent2.putExtra("student", intentToGet.getStringExtra("student"));
    intent2.putExtra("pass", intentToGet.getStringExtra("pass"));
    intent2.putExtra("un", intentToGet.getStringExtra("un"));
    spec2 = tabHost
            .newTabSpec("notes")
            .setIndicator("Notes")
            .setContent(intent2);
    tabHost.addTab(spec2);

    tabHost.setCurrentTab(1);   
}

}

Any ideas?

  • 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-09T02:28:24+00:00Added an answer on June 9, 2026 at 2:28 am

    In the past I have had to do something similar and solved it by doing the following:

    1. Create a static boolean variable CAN_LOAD = false and HAS_LOADED = false in your HoursActivity class.
    2. Once whatever needs to happen in the NotesActivity that will allow your HoursActivity class to be loaded, set CAN_LOAD to true.
    3. In HoursActivity, on your onCreate and onResume call the loading function you want to be run, and within that function test for CAN_LOAD == true && HAS_LOADED == false and and load only if both pass, setting HAS_LOADED = true in the function so that it does not get run multiple times.

    So when you click on the tab, the onResume will be called and the Activity can do whatever set up is needed. There may be a problem with performance if the load function is slow to perform, in which case you will need to modify it slightly to not wait until the onResume to load (keeping it async). But that should at least get you started off.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.