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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:34:17+00:00 2026-06-14T19:34:17+00:00

I have the MainActvity class which contains a Tab (indicator as Tab) Here is

  • 0

I have the MainActvity class which contains a Tab (indicator as Tab)

Here is my code:-

public class MainActivity extends TabActivity {
TabHost tabHost;
Context context = MainActivity.this;
TabSpec spec;

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

    TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost
            .newTabSpec("Tab")
            .setIndicator("Tab")
            .setContent(
                    new Intent(this, MyActivityGroup.class)
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

    tabHost.setCurrentTab(0);

}

}

this internally calling MyActvityGroup which extends the ActvityGroup class as.

public class MyActivityGroup extends ActivityGroup {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // you van get the local activitymanager to start the new activity

    View view = getLocalActivityManager().startActivity(
            "ReferenceName",
            new Intent(this, NewActivity.class)
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
            .getDecorView();
    this.setContentView(view);

}
}

in NewActvity,java file i have done something like

public class NewActivity extends Activity {

Button btnGo;

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

    setContentView(R.layout.new_activity);

    btnGo = (Button) findViewById(R.id.btnStartActivity);
    btnGo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Toast.makeText(NewActivity.this, "Clicked", Toast.LENGTH_SHORT)
                    .show();

            Intent intent = new Intent();
            intent.setClass(getParent(), ButtonActivity.class);
            startActivity(intent);

        }
    });

}
}
  • now here this activity contains a button.
  • I want to start the new activity in the same tab area on the click event of this button, but it start in the full screen mode. I am not able to see my tab any more.
  • How can I start the activity in the current tab container.
  • I there something wrong with my ActvityGroup class or I am not starting the activity in the proper manner..?
  • 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-14T19:34:18+00:00Added an answer on June 14, 2026 at 7:34 pm

    Use below code instead of your code, it will solve your problem.

    MyActivityGroup.java

    public class MyActivityGroup extends ActivityGroup {
    
        private Stack<String> stack;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (stack == null) {
                stack = new Stack<String>();
            }
    
            push("HomeStackActivity", new Intent(this, NewActivity.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()
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                Window newWindow = manager.startActivity(stack.peek(), lastIntent);
                setContentView(newWindow.getDecorView());
            }
        }
    }
    

    NewActivity.java

    public class NewActivity extends Activity {
    
        Button btnGo;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.new_activity);
    
            btnGo = (Button) findViewById(R.id.btnStartActivity);
            btnGo.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    Toast.makeText(NewActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
    
                    Intent intent = new Intent();
                    intent.setClass(getParent(), ButtonActivity.class);
                    MyActivityGroup activityStack = (MyActivityGroup) getParent();
                    activityStack.push("Button Activity", intent);                    
                }
            });
        }
    }
    

    And Please see below link for more information.

    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

I have 2 tabs, named : Tab1, Tab2 class MainActivity extends TabActivity. MainActivity.java public
I have the following class: public class MainActivity extends Activity { /** Called when
I have a mapview class which extends MapActivity. The code i'm using follows the
(I have got class MainActivity (extends Activity) and there I have got method setContentView(GameView);
I have a class which extends ListActivity within I have all methods for managing
If I have a string variable inside one class MainActivity.selectedFilePath which has a value
I have an activity ( MainActivity.java ) in which content view is like this
have written this little class, which generates a UUID every time an object of
I have a mainActivity which is Customer.java with listview of 5 diff. activities. I
I have developed some reusable android component which is basically a class . This

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.