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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:48:40+00:00 2026-05-25T21:48:40+00:00

My question is switching between tab using activity group it want to display last

  • 0

My question is switching between tab using activity group it want to display last activity.
I want to show last open/visited screen when we navigate the tab.My one is go to first screen:

This is my maninActivity’

    public class MainActivity extends TabActivity {
    int selectedTab;
    TabHost tabHost ;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabview);

        TabHost t = getTabHost();
        tabHost = (TabHost)findViewById(android.R.id.tabhost);
        Resources res = getResources();
        TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
        TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");
        TabSpec fouthTabSpec = tabHost.newTabSpec("tid1");
        /** TabSpec setIndicator() is used to set name for the tab. */
        /** TabSpec setContent() is used to set content for a particular tab. */
        firstTabSpec.setIndicator("Sales",res.getDrawable(R.drawable.ic_tab_artists_grey)).setContent(new Intent(this,SalesActivityGroup.class));
        secondTabSpec.setIndicator("Admin",res.getDrawable(R.drawable.admin)).setContent(new Intent(this,SettingActivityGroup.class));
        thirdTabSpec.setIndicator("Setting",res.getDrawable(R.drawable.ic_tab_artists_grey)).setContent(new Intent(this,SettingActivityGroup.class));
        fouthTabSpec.setIndicator("Inquiry",res.getDrawable(R.drawable.ic_tab_artists_grey)).setContent(new Intent(this,SettingActivityGroup.class));

        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);
        tabHost.addTab(thirdTabSpec);
        tabHost.addTab(fouthTabSpec);
        tabHost.setCurrentTab(0);
        tabHost.setMinimumHeight(18);
        tabHost.setFadingEdgeLength(5);

    }

    public void onTabChanged(String arg0) {
            selectedTab = tabHost.getCurrentTab();

    }
}

This is my SalesActivityGroup

    public class SalesActivityGroup extends ActivityGroup {

    public static SalesActivityGroup group;
    private ArrayList<View> history;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.history = new ArrayList<View>();
        group = this;

        View view = getLocalActivityManager().startActivity("Sales",
                new Intent(this, SalesRouteActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .getDecorView();

        replaceView(view);

    }

    public void replaceView(View v) {
        history.add(v);
        setContentView(v);

    }

    public void back() {
        if (history.size() > 0) {
            history.remove(history.size() - 1);
            if (history.size() > 0) {
                setContentView(history.get(history.size() - 1));
            } else {
                finish();
            }
        } else {
            finish();
        }
    }

    public void backToFirst() {
        int size = history.size();
        while (size > 1) {
            history.remove(size - 1);
            size = history.size();
        }
        setContentView(history.get(0));
    }

    @Override
    public void onBackPressed() {
        SalesActivityGroup.group.back();
        return;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //  super.onActivityResult(requestCode, resultCode, data);
        Log.i("****" , "requestCode" + requestCode);
        Bundle bundle = data.getExtras();
        String roteCode = bundle.getString("RouteCode");
        Intent intent = new Intent(SalesActivityGroup.this,ListRetailerActivity.class);
        bundle.putString("RouteCode", roteCode);
        intent.putExtras(bundle);
        View view = SalesActivityGroup.group.getLocalActivityManager()
                .startActivity("",intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
        SalesActivityGroup.group.replaceView(view);
        }


}

This is my calling part in SalesRouteActivity

Intent intent = new Intent(SalesRouteActivity.this, ListRetailerActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("RouteName", keyword);
                        intent.putExtras(bundle);
            View view = SalesActivityGroup.group.getLocalActivityManager().startActivity("", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();  
            SalesActivityGroup.group.replaceView(view);

Same like above code , i have Setting ActivityGroup for next tab

public class SettingActivityGroup extends ActivityGroup {

    // Keep this in a static variable to make it accessible for all the nested
    // activities, lets them manipulate the view
    public static SettingActivityGroup group;

    // Need to keep track of the history if you want the back-button to work
    // properly, don't use this if your activities requires a lot of memory.
    private ArrayList<View> history;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.history = new ArrayList<View>();
        group = this;

        // Start the root activity withing the group and get its view
        View view = getLocalActivityManager().startActivity(
                "Setting",
                new Intent(this, SettingScreenActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .getDecorView();

        // Replace the view of this ActivityGroup
        replaceView(view);

    }

    public void replaceView(View v) {
        // Adds the old one to history
        history.add(v);
        // Changes this Groups View to the new View.
        setContentView(v);

    }


    public void back() {
        if (history.size() > 0) {
            history.remove(history.size() - 1);
            if (history.size() > 0) {
                setContentView(history.get(history.size() - 1));
            } else {
                finish();
            }
        } else {
            finish();
        }
    }

    @Override
    public void onBackPressed() {
        SettingActivityGroup.group.back();
        return;
    }

}

I pasted my code here.
http://pastebin.com/D4fvkGBx

I am facing trouble on this…

Please help me

Where is wrong in my code?

Thanks in advance

  • 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-25T21:48:41+00:00Added an answer on May 25, 2026 at 9:48 pm

    There were some issue in my MainActivity class

      tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;
    
        intent = new Intent().setClass(this, SalesActivityGroup.class);  
        spec = getTabHost().newTabSpec("Sales").setIndicator("Sales",getResources().getDrawable(R.drawable.sales )).setContent(intent);
        tabHost.addTab(spec);
    
        intent = new Intent().setClass(this, SettingActivityGroup.class);  
        spec = getTabHost().newTabSpec("Admin").setIndicator("Admin",getResources().getDrawable(R.drawable.admin1)).setContent(intent);
        tabHost.addTab(spec);
    
        intent = new Intent().setClass(this, SettingActivityGroup.class);  
        spec = getTabHost().newTabSpec("Setting").setIndicator("Setting",getResources().getDrawable(R.drawable.maintenance)).setContent(intent);
        tabHost.addTab(spec);
    
        intent = new Intent().setClass(this, SettingActivityGroup.class);  
        spec = getTabHost().newTabSpec("Inquiry").setIndicator("Inquiry",getResources().getDrawable(R.drawable.inquiry)).setContent(intent);
        tabHost.addTab(spec);
    
        tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.selected_tab);
    
    
        tabHost.setCurrentTab(0);
        tabHost.setMinimumHeight(18);
        tabHost.setFadingEdgeLength(5);
        tabHost.setFocusable(true); 
        tabHost.requestFocus();
        tabHost.setFadingEdgeLength(5);
    

    No need to call findById() here.

    Here was wrong tabHost = (TabHost)findViewById(android.R.id.tabhost);

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

Sidebar

Related Questions

I have written tab for my android application. My question is switching between tab
My question about the reconfiguration delay when switching between Access 2003 and 2007 the
I have used tabbar with activity group in my application. I have four tab
Thinking about a solution to my previous question about switching between numerical and analytical
Here's my previous question about switching C callstacks. However, C++ uses a different calling
Question is pretty self explanitory. I want to do a simple find and replace,
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
I have a container which switches its main content between several screen-sized panes. I'm
Switching between different iphone views is a regular thing I need to do. I
I am building a tabbed interface for switching between various similar layers. Each layer

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.