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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:40:08+00:00 2026-05-28T16:40:08+00:00

I have a project with two tabs. Tabs are created in the main class.

  • 0

I have a project with two tabs. Tabs are created in the main class. Here I added the tablistener too, to handle the changes between the tabs. Here is one tab’s instant:

TabHost tabHost = getTabHost();    
tabHost.setOnTabChangedListener(this);
    TabHost.TabSpec spec;
    Intent intent;
    intent = new Intent().setClass(this, Tab1.class);
    spec = tabHost.newTabSpec("tab1").setIndicator("",
                    res.getDrawable(R.drawable.ic_tab_tab1))
                    .setContent(intent);
            tabHost.addTab(spec);

The listener method:

public void onTabChanged(String tabName) {
    if (tabName.equals("tab1")){
        tab1.load();
    }
}

And similar for the second tab too. My question is, if the onCreate() methods run only once in the Tab1 and Tab2 classes, how can I “force” the main class to show the corresponding Activity after the tab changes? I receive NullPointerException

The tabs’ classes are something like this:

    public class Tab1 extends Activity{
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          setContentView(R.layout.tab1);
          load();
      }
      public void load(){
        //....
      }
    }
  • 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-28T16:40:08+00:00Added an answer on May 28, 2026 at 4:40 pm

    onCreate() method calls only once when your Activity first time loaded.

    If you want to perform any functionality on each time you view your Activity, put that functionality in onResume() method.

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

Sidebar

Related Questions

I have a project consisting of two files, main.c and logoff.c. When I try
I have several projects open in an Eclipse workspace. Like so: com.harbl.project.one com.harbl.project.two com.harbl.project.three
I have a project that generates applications for two targets. One of the targets
My project have two main requirements 1) Different set of rules applied to same
I have a project with two Info.plist files (one for each target). In the
I currently have my project running two separate threads (one for MFC operations, like
I have small project consisting of one maven project and two maven modules. One
I (unfortunately) have a MATLAB project with two files, main.m and function.m . I
I have made two targets in my project. One for a Staging version and
I have a project with two targets, one is a Cocoa Static Library, the

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.