@Override public boolean onContextItemSelected(android.view.MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int menuItemIndex = item.getItemId(); if (menuItemIndex == DOWNLOAD_DELETE_DOWNLOAD) { // We are going to take the first element if (_menuItemSelected.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) { final File f = new File(((PutlockerDownloadJob) _menuItemSelected).getFileLocation()); // does the file exist? if (f.exists()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.delete_file); builder.setMessage(R.string.would_you_like_to_delete_file); builder.setPositiveButton( R.string.yes, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { f.delete(); getPutlockerApplication().getStorage().deleteTyped(_menuItemSelected); doAddItems(); _menuItemSelected = null; } }); builder.setNegativeButton( R.string.no, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getPutlockerApplication().getStorage().deleteTyped(_menuItemSelected); doAddItems(); _menuItemSelected = null; } }); builder.setCancelable(false).create().show(); } else { getPutlockerApplication().getStorage().deleteTyped(_menuItemSelected); doAddItems(); _menuItemSelected = null; } } else { getPutlockerApplication().getStorage().deleteTyped(_menuItemSelected); doAddItems(); _menuItemSelected = null; } } else if (menuItemIndex == DOWNLOAD_STOP_DOWNLOAD) { DownloadService service = getPutlockerApplication().getService(); if (service != null) { service.cancelJob(_menuItemSelected); } _menuItemSelected = null; } return true; }