5

我正在创建一个有一些线程的应用程序,我想关闭它。我试过:

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;
}
4

1 回答 1

0

最后我通过停止线程解决了它。谢谢大家

于 2014-04-30T14:15:24.670 回答