Android 程序真退出与假退出后台运行详解
2012-06-01 15:36
405 查看
public void onBackPressed() {
AlertDialog.Builder builder = new Builder(LawdaquanActivity.this);
builder.setIcon(R.drawable.imagebutton5);
builder.setTitle("提示");
builder.setMessage("你真的要退出法律信息软件吗?");
builder.setPositiveButton("是",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
}
});
builder.setNegativeButton("否",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
-------------真退出
退出应用程序的实现:可以自己写个方法,例如:
public void exitProgrames{
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
android.os.Process.killProcess(android.os.Process.myPid());
--------------重写ONKEYDOWN
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
new AlertDialog.Builder(this)
.setIcon(R.drawable.title)
.setTitle("退出软件")
.setMessage("是否退出法律文书软件")
.setPositiveButton("否",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
}).setNegativeButton("退出", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
}).create().show();
}
else {
return super.onKeyDown(keyCode, event);
}
// TODO Auto-generated method stub
return super.onKeyDown(keyCode, event);
}
-----------假退出
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
finish();
AlertDialog.Builder builder = new Builder(LawdaquanActivity.this);
builder.setIcon(R.drawable.imagebutton5);
builder.setTitle("提示");
builder.setMessage("你真的要退出法律信息软件吗?");
builder.setPositiveButton("是",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
}
});
builder.setNegativeButton("否",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
-------------真退出
退出应用程序的实现:可以自己写个方法,例如:
public void exitProgrames{
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
android.os.Process.killProcess(android.os.Process.myPid());
--------------重写ONKEYDOWN
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
new AlertDialog.Builder(this)
.setIcon(R.drawable.title)
.setTitle("退出软件")
.setMessage("是否退出法律文书软件")
.setPositiveButton("否",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
}).setNegativeButton("退出", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
}).create().show();
}
else {
return super.onKeyDown(keyCode, event);
}
// TODO Auto-generated method stub
return super.onKeyDown(keyCode, event);
}
-----------假退出
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
finish();
相关文章推荐
- Android程序真退出与假退出后台运行详解
- Android程序真退出与假退出后台运行详解
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- android实现程序的后台运行 and 完全退出
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- Android(安卓)内存分配机制详解 不需要关闭后台运行程序
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- Android按下返回键后,程序不退出,进入后台运行。使用moveTaskToBack(boolean nonRoot)
- Android按返回键退出程序但不销毁,程序后台运行,同QQ退出处理方式
- android退出程序 后台运行 实现退出键和home键一样的效果
- android点击Back键不退出程序,在后台运行
- Android按返回键程序仍在后台运行,并未完全退出和销毁,类似微信QQ等退出方式的实现-- moveTaskToBack
- android实现程序的后台运行
- Android SurfaceView运行机制剖析--处理切换到后台再重新进入程序时的异常
- Android 程序后台运行时Timer定时器不启用
- android 程序强制停止后服务后台启动运行 ---- 不同程序间相助 使用第三方服务