我的目标是,当您按下选项卡时,在选项卡栏上会显示不同的活动,但在其中一个活动上,我不希望任何活动只显示一个电子邮件帐户选择器来显示导致电子邮件编写器的活动。
我目前的方法适用于 2.2 和 2.3,但不适用于更高版本。所以在 Galaxy 3s 上我得到
Caused by: java.lang.SecurityException: Given caller package android is not running in process ProcessRecord{}
这是我当前的代码,如果您有建设性的批评,我也愿意做更好的方法。
公共类 myTabbar 扩展 TabActivity {
TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();
setTabs();
}
private void setTabs() {
addTab("Home", R.drawable.home, Home_Page_Activity.class);
addTab("Map", R.drawable.map, Map_Locations_Activity.class);
addTab("Email", R.drawable.email, Email_From_Tab.class);
addTab("Input", R.drawable.suggestions, Suggestions_Activity.class);
addTab("More", R.drawable.more, More.class);
}
private void addTab(String labelId, int drawableId, Class<?> c) {
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
if(c == Email_From_Tab.class){
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"email@emael.com"};
String[] ccs={"email@emael.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.setType("message/rfc822");
spec.setContent(Intent.createChooser(it, "Choose Email Client"));
}else{
spec.setContent(intent);
}
tabHost.addTab(spec);
}
}