1

i want to avoid starting activity in the first tab.. I set tab 2 as default tab using tabHost.setCurrentTab(1). When the tab activity starts, I expect that only the activity in tab 2 gets started. But, currently, Android starts both activity in tab 1 and activity in tab 2, if I set tab 2 as default current tab

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

@SuppressWarnings("deprecation")

public class sample1 extends TabActivity {
    String postContent;

    public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);  

        setContentView(R.layout.main2);
        Bundle bundle = this.getIntent().getExtras();
        postContent = bundle.getString("url");
             Log.d("securl1",postContent);
        Resources ressources = getResources(); 
        TabHost tabHost = getTabHost(); 

        // Android tab


        // Apple tab
        Intent intentApple = new Intent().setClass(this, AppleActivity.class);
        intentApple.putExtra("url", postContent);
        TabSpec tabSpecApple = tabHost
            .newTabSpec("Apple")
            .setIndicator("Web")
            .setContent(intentApple);

        // Windows tab
        Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
        TabSpec tabSpecWindows = tabHost
            .newTabSpec("Windows")
            .setIndicator("Smart")
            .setContent(intentWindows);

        // Blackberry tab
        Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
        intentBerry .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabSpecBerry = tabHost
            .newTabSpec("Berry")
            .setIndicator("", ressources.getDrawable(R.drawable.ic_menu_share_holo_dark))
            .setContent(intentBerry);


        Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
        intentAndroid .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabSpecAndroid = tabHost
            .newTabSpec("Android")
            .setIndicator("", ressources.getDrawable(R.drawable.ic_menu_back))

            .setContent(intentAndroid);


        Intent intentBerry1 = new Intent().setClass(this, BlackBerryActivity1.class);
        TabSpec tabSpecBerry1 = tabHost
            .newTabSpec("Berry")
            .setIndicator("berry")
            .setContent(intentBerry1);

        // add all tabs 
        tabHost.addTab(tabSpecAndroid);
        tabHost.addTab(tabSpecApple);
        tabHost.addTab(tabSpecWindows);
        tabHost.addTab(tabSpecBerry);

        //set Windows tab as default (zero based)
        tabHost.setCurrentTab(1);
    }

}
  • Why you not swap tab2 and tab1 ? so which indirectly start tab2 activity first as tab1. – Haresh Chhelana Dec 04 '14 at 06:42
  • TabActivity is deprecated. Please use Actionbar with Tabs – Hardik Trivedi Dec 04 '14 at 06:45
  • actually i want to execute my second tab as starting...wen i move to tab one it will go back to previous activity... –  Dec 04 '14 at 06:49
  • @HareshChhelana my design gonna change bro...if i do that...i want to prevent loading my first tab activity...pls give some idea –  Dec 04 '14 at 07:36
  • possible duplicate of [How to avoid starting the activity at the first tab in a TabActivity?](http://stackoverflow.com/questions/27289697/how-to-avoid-starting-the-activity-at-the-first-tab-in-a-tabactivity) – rekire Mar 03 '15 at 09:19
  • You should not dublicate your questions. – rekire Mar 03 '15 at 09:20

0 Answers0