我正在制作一个应用程序,我在其中设置了两个底部选项卡,
即“退出”和“返回”。
现在我想通过单击“退出”选项卡(不是按钮)退出应用程序。
我该怎么做,我知道在 android 中我们永远无法真正关闭应用程序,但我想在单击“退出”时转到主屏幕。
我还研究了以下链接以及其他链接
Is quitting an application frowned upon?
编辑
public class Man_age_ur_PhoneActivity extends TabActivity {
/** Called when the activity is first created. */
ListView listview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homepage);
setTabs();
}
private void setTabs()
{
addTab("Exit", R.drawable.tab_exit);
addTab("Back", R.drawable.tab_back);
//To add more tabs just use addTab() method here like previous line.
}
private void addTab(String labelId, int drawableId)
{
TabHost tabHost = getTabHost();
// Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("" + 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);
// spec.setContent(intent);
tabHost.addTab(spec);
}
}
最佳答案
单击第二个选项卡时,您只需编写“finish();”。这将关闭之前打开的 Activity ,您可以退出您的应用程序。
关于android - 想要在单击选项卡时退出应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8758012/