1.在MainActivity上加入Back Button的監聽實做:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK) { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: finish(); break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("退出後現有下載的檔案進度將會停止,確定退出?").setPositiveButton("退出", dialogClickListener) .setNegativeButton("否", dialogClickListener).show(); return true; } return super.onKeyDown(keyCode, event); }
2.在下載檔案的MainActivity onDestroy()中加入:
@Override protected void onDestroy(){ super.onDestroy(); DownloadFile.getNowDownloadTask().cancel(true); }
沒有留言:
張貼留言