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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:32:22+00:00 2026-06-15T21:32:22+00:00

Possible Duplicate: start Activity from an other Activity with Tabs see the following two

  • 0

Possible Duplicate:
start Activity from an other Activity with Tabs

enter image description hereenter image description here

see the following two pictures, i want to click the icon “all songs” and then jump to a playlist. but i do not know how to use TabHost and display on the playlist? How to let TabHost show in every Activity?

the code of Activity has TabHost:

/*package com.lxy.musicplayer.view;

import com.lxy.musicplayer.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Window;
import android.widget.TabHost;

public class BuddleTabHostActivity extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        TabHost tab  = getTabHost();
//        LayoutInflater.from(this).inflate(R.layout.tabhost_layout, tab.getTabContentView(),true);

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tabhost_layout);


        addIntentActivity(tab, MainActivity.class, "all songs");
        addIntentActivity(tab, MainActivity.class, "Network songs ");
        addIntentActivity(tab, MainActivity.class, "my set");

        tab.setCurrentTab(0);


    }


    private void addIntentActivity(TabHost tab,Class c,String title){
        Intent intent = new Intent();
        intent.setClass(this, c);

        TabHost.TabSpec spec = tab.newTabSpec(title);
        spec.setIndicator(title);
        spec.setContent(intent);
        tab.addTab(spec);

    }


}
*/

package com.lxy.musicplayer.view;

import com.lxy.musicplayer.R;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;

public class BuddleTabHostActivity extends TabActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tabhost_layout);
        //get switching object
        TabHost tab=getTabHost();
        addIntentActivity(tab, MainActivity.class,"local");
        addIntentActivity(tab, PlayActivity.class,"favorite");
        addIntentActivity(tab, PlayListActivity.class,"online");
        addIntentActivity(tab, MainActivity.class,"setting");
        //executive tab default
        tab.setCurrentTab(0);
    }

    public void addIntentActivity(TabHost tab,Class<?> c,String str){
        Intent intent=new Intent();
        intent.setClass(this, c);
        //switching object and obtain tab
        TabHost.TabSpec spec=tab.newTabSpec(str);
        //set tab information
        //turn to the page display
        spec.setIndicator(str);
        spec.setContent(intent);
        //add tabs
        tab.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-06-15T21:32:24+00:00Added an answer on June 15, 2026 at 9:32 pm

    Please write below code for that, it will solve your problem.

    ActivityStack.java

    private Stack<String> stack;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (stack == null)
            stack = new Stack<String>();
        // start default activity
        push("FirstStackActivity", new Intent(this, Tab_SampleActivity.class));
    }
    
    @Override
    public void finishFromChild(Activity child) {
        pop();
    }
    
    @Override
    public void onBackPressed() {
        pop();
    }
    
    public void push(String id, Intent intent) {
        Window window = getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        if (window != null) {
            stack.push(id);
            setContentView(window.getDecorView());
        }
    }
    
    public void pop() {
        if (stack.size() == 1)
            finish();
        LocalActivityManager manager = getLocalActivityManager();
        manager.destroyActivity(stack.pop(), true);
        if (stack.size() > 0) {
            Intent lastIntent = manager.getActivity(stack.peek()).getIntent();
            Window newWindow = manager.startActivity(stack.peek(), lastIntent);
            setContentView(newWindow.getDecorView());
        }
    }
    

    TabActivity.java

    public class TabActivity extends TabActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tab_screen);
            TabHost tabHost = getTabHost();
            Intent intent = new Intent().setClass(this, ActivityStack.class);
            TabHost.TabSpec spec = tabHost.newTabSpec("tabId").setIndicator("Temp", getResources().getDrawable(R.drawable.home));
            spec.setContent(intent);
    
            tabHost.addTab(spec);
    
            Intent intent1 = new Intent().setClass(this, ActivityStack.class);
            TabHost.TabSpec spec1 = tabHost.newTabSpec("tabId").setIndicator("Temp", getResources().getDrawable(R.drawable.invoice));
            spec1.setContent(intent1);
            tabHost.addTab(spec1);
    
            tabHost.setCurrentTab(0);
        }
    }
    

    FirstActivity.java

    public class FirstActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textView = new TextView(this);
            textView.setText("Tab Sample Activity ");
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(getParent(), SecondActivity.class);
                    ActivityStack activityStack = (ActivityStack) getParent();
                    activityStack.push("SecondActivity", intent);
                }
            });
            setContentView(textView);
        }
    }
    

    SecondActivity.java

    public class SecondActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textView = new TextView(this);
            textView.setText("First Stack Activity ");
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(getParent(), ThirdActivity.class);
                    ActivityStack activityStack = (ActivityStack) getParent();
                    activityStack.push("ThirdActivity", intent);
                }
            });
            setContentView(textView);
        }
    }
    

    ThirdActivity.java

    public class ThirdActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
    }
    

    Add Below XML files into your res/layout folder.

    1) tab_screen.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:padding="3dp" >
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@android:id/tabs"
                android:layout_weight="1" />
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" />
        </RelativeLayout>
    
    </TabHost>
    

    2) main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
    </LinearLayout>
    

    AndroidManifest.xml:-

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.tabsample"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk android:minSdkVersion="8" />
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:name=".FirstActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
            <activity
                android:name=".TabActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".ActivityStack"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
            <activity
                android:name=".SecondActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
            <activity
                android:name=".ThirdActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    

    And see below link for more information with complete example.

    Multiple Android Activities in a TabActivity

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

Sidebar

Related Questions

Possible Duplicate: start Activity from an other Activity with Tabs I have a TabHost
Possible Duplicate: Where can I learn web programming from start to mastery? I want
Possible Duplicate: How to start a process from C#? I want to start a
Possible Duplicate: How to start an Activity from a Service? apologies for my terminology
Possible Duplicate: How to start an Activity from a Service? Could some one please
Possible Duplicate: Start android application without activity I want to do a download tool
Possible Duplicate: launch facebook app from other app Till few days ago, in order
Possible Duplicate: launch facebook app from other app I am doing one android project,
Possible Duplicate: Launching intent from a class outside an activity I was just wondering
Possible Duplicate: How to pass image data from one activity to another activity? pass

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.