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

The Archive Base Latest Questions

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

I have a TabHost with two child activities in it (in two tabs). I

  • 0

I have a TabHost with two child activities in it (in two tabs). I also implemented a public function in one of these activities that i would like to call from my parent (TabHost), to trigger some action within the tab.

Is it possible to reference the activity itself from the TabHost to call a public function?

Thanks

here is my tabhost setup:

    res = getResources(); 
    tabHost = getTabHost(); 

    TabHost.TabSpec spec; 
    Intent intent;  

    intent = new Intent().setClass(this, home.class);
    spec = tabHost.newTabSpec("home").setIndicator("Groups", res.getDrawable(R.drawable.groups)).setContent(intent);
    tabHost.addTab(spec);
    intent = new Intent().setClass(this, messages.class);
    spec = tabHost.newTabSpec("messages").setIndicator("Messages", res.getDrawable(R.drawable.messages)).setContent(intent);    
    tabHost.addTab(spec);
  • 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-20T20:18:46+00:00Added an answer on May 20, 2026 at 8:18 pm

    My approach would be to define a nested ‘listener’ class in the child activity which extends BroadcastReceiver.

    I would then simply broadcast an Intent from my TabActivity which would then trigger the BroadcastReceiver to perform the action.

    EDIT: To give example code…

    The steps are…

    1. Define the intent filter in the manifest
    2. Add the nested ‘listener’ to the child activity
    3. Set onResume()/onPause() in child activity to register/unregister the listener
    4. Create intent in TabActivity and broadcast it when you want child to do something

    In AndroidManifest.xml

    <activity
        android:name=".MyActivity"
        android:label="@string/app_name"
        <intent-filter>
            <action android:name="com.mycompany.myApp.DO_SOMETHING" />
        </intent-filter>
    </activity>
    

    In MyActivity.java

    public class MyActivity extends Activity {
    
        private MyListener listener = null;
        private Boolean MyListenerIsRegistered = false;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreated(savedInstanceState);
    
            listener = new MyListener();
        }
    
        @Override
        protected void onResume() {
            super.onResume();
    
            if (!MyListenerIsRegistered) {
                registerReceiver(listener, new IntentFilter("com.mycompany.myApp.DO_SOMETHING"));
                MyListenerIsRegisterd = true;
            }
        }
    
        @Override
        protected void onPause() {
            super.onPause();
    
            if (MyListenerIsRegistered) {
                unregisterReceiver(listener);
                MyListenerIsRegistered = false;
            }
        }
    
        // Nested 'listener'
        protected class MyListener extends BroadcastReceiver {
    
            @Override
            public void onReceive(Context context, Intent intent) {
    
                // No need to check for the action unless the listener will
                // will handle more than one - let's do it anyway
                if (intent.getAction().equals("com.mycompany.myApp.DO_SOMETHING")) {
                    // Do something
                }
            }
        }
    }
    

    In the main TabActivity

    private void MakeChildDoSomething() {
    
        Intent i = new Intent();
        i.setAction("com.mycompany.myApp.DO_SOMETHING");
        sendBroadcast(i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one activity in which I am having one TabHost with two tabs.
I have a TabActivity that has a TabHost with two tabs. Each tab has
I have TabHost with three tabs. One of these tabs contains ListActivity. I want
I have a TabHost activity that are switching activities, so my main looks like
Currently I have a TabHost implemented with 3 tabs each containing a separate activity.
I want to create application with two Tabs, like follow: MainClass: private TabHost tabHost;
I have a tabHost with three activities, one of them is meant for taking
I have a tabhost with some tabs, and each tab have implemented the method
Hey, I have a TabHost with two tabs, each with an Activity. The first
I need to have a TabHost consisting of two tabs where each tab represented

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.