我正在创建一个有一些线程的应用程序,我想关闭它。我试过:
System.exit(0);
但是应用程序会自行重启。
请帮帮我,谢谢。
编辑:
OnDestroy代码:
@Override
public void onDestroy(){
android.os.Process.killProcess(android.os.Process.myPid());
}
OnOptionsItemClicked:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
startActivity(new Intent(this, ConnActivity.class));
finish();
break;
case R.id.item2:
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
break;
case R.id.item3:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Mensaje al servidor");
alert.setMessage("Enviar mensaje al servidor");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Enviar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
MessageRequest msqr = new MessageRequest();
msqr.msg = new Packets.Message();
msqr.msg.lidfrom = pi.getPhoneLoginIdentifier();
msqr.msg.lidto = new LoginIdentifier("SERVER","SERVER","-1");
msqr.msg.msg = value;
setTime(msqr.msg);
send(msqr);
}
});
alert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
try{
alert.show();
}catch(Exception e){
}
break;
}
return true;
}
答案 0 :(得分:0)
最后我通过停止线程来解决它。谢谢所有