我想避免在第一个标签中启动活动..我使用tabHost.setCurrentTab(1)将标签2设置为默认标签。选项卡活动开始时,我预计只有选项卡2中的活动才会启动。但是,目前,如果我将标签2设置为默认的当前标签,则Android会启动标签1中的活动和标签2中的活动
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);
}
}