Switching between tab using activity group it want to  display last activity
<p>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:</p>

<p>This is my maninActivity'</p>

<pre><code>    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();

    }
}
</code></pre>

<p>This is my SalesActivityGroup</p>

<pre><code>    public class SalesActivityGroup extends ActivityGroup {

    public static SalesActivityGroup group;
    private ArrayList&lt;View&gt; history;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.history = new ArrayList&lt;View&gt;();
        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() &gt; 0) {
            history.remove(history.size() - 1);
            if (history.size() &gt; 0) {
                setContentView(history.get(history.size() - 1));
            } else {
                finish();
            }
        } else {
            finish();
        }
    }

    public void backToFirst() {
        int size = history.size();
        while (size &gt; 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);
        }


}
</code></pre>

<p>This is my calling part in SalesRouteActivity</p>

<pre><code>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);
</code></pre>

<p>Same like above code , i have Setting ActivityGroup for next tab</p>

<pre><code>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&lt;View&gt; history;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.history = new ArrayList&lt;View&gt;();
        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() &gt; 0) {
            history.remove(history.size() - 1);
            if (history.size() &gt; 0) {
                setContentView(history.get(history.size() - 1));
            } else {
                finish();
            }
        } else {
            finish();
        }
    }

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

}
</code></pre>

<p>I pasted my code here.
<a href="http://pastebin.com/D4fvkGBx" rel="nofollow">http://pastebin.com/D4fvkGBx</a></p>

<p>I am facing trouble on this...</p>

<p>Please help me </p>

<p>Where is wrong in my code?</p>

<p>Thanks in advance</p>
