如何在android中关闭整个应用程序
可能的重复:
Android:如何杀死应用程序及其所有活动?
我尝试使用finish()。
但它只是关闭当前活动而不是整个应用程序。 当另一个活动正在运行时,隐藏它会在我完成上述活动时显示。
代码:
public class third extends Activity{
Button btn_back, btn_finish;
Intent intent2;
Bundle b1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
intent2 = getIntent();
b1=intent2.getExtras();
String spin = b1.getString("name");
String gender = b1.getString("gender");
btn_back = (Button) findViewById(R.id.button1);
btn_finish = (Button) findViewById(R.id.button2);
Toast.makeText(third.this, spin + "" + gender , Toast.LENGTH_SHORT).show();
btn_back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
intent2 = new Intent (third.this,second.class);
startActivity(intent2);
}
});
btn_finish.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
Possible Duplicate:
Android: How to kill an application with all it's activities?
I tried with finish().
But it just close the present activity not whole application.
as the another activity is running hide it shows when i finish the above activity..
CODE :
public class third extends Activity{
Button btn_back, btn_finish;
Intent intent2;
Bundle b1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
intent2 = getIntent();
b1=intent2.getExtras();
String spin = b1.getString("name");
String gender = b1.getString("gender");
btn_back = (Button) findViewById(R.id.button1);
btn_finish = (Button) findViewById(R.id.button2);
Toast.makeText(third.this, spin + "" + gender , Toast.LENGTH_SHORT).show();
btn_back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
intent2 = new Intent (third.this,second.class);
startActivity(intent2);
}
});
btn_finish.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用这行代码:
integer
1 只是一个返回码。编辑
当我第一次开始android开发时就回答了这个问题:请不要使用它。您可以尝试向 Android 应用程序添加退出按钮。
Use this line of code:
The
integer
1 is just a return code.EDIT
This was answered when I first started android development: Please do not use it. You could try Adding an Exit button to Android Application.