Maybe you can use System.exit(0)
if you want to kill your app.
As came up from comments, you need to do it from the main activity. My way (though there might be a cleaner way) is to add a static handler in the main activity:
static Handler handler = new Handler() {
@Override
public void handleMessage(Message msg)
{
System.exit(2);
}
}
and a static method:
static public Handler getExitHandler()
{
return handler;
}
and in each class I obtain this handler and send it a message when I want to exit:
MyMainActivity.getExitHandler().sendEmptyMessage(0);
again, not so clean, but the same about System.exit(2);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…