I have android application which contain daily database backup facility & contain clear facility.I saved backupdatabse like this
DBBackup -- dir
2012-01-25 -dir
userventura.db -file
2012-01-25 -dir
userventura.db -file
Like wise i saved.
Problem is deleting directory. For example if user select the date 2012-01-28 this , then it need to remove previous directory . In otherwords compare with user select date & directory date, then it will delete those files.
My problem is I couldn't remove the Directory.It removing the file userventura.db
.
private class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
private final ProgressDialog dialog = new ProgressDialog(getDialogContext());
String strDate = disdbClrDate.getText().toString();
protected void onPreExecute() {
this.dialog.setMessage("MicroSD card Clear..");
this.dialog.show();
}
protected Boolean doInBackground(final String... args) {
File exportDir = new File(Environment.getExternalStorageDirectory(), "databaseBaup/");
if (!exportDir.exists()) {
exportDir.mkdirs();
}
try {
String[] sample = exportDir.list();
for(int i =0;i < sample.length;i++){
File dirc = new File(exportDir, sample[i]);
File file = new File(exportDir, sample[i]+"/userventura.jpeg");
if(dirc.getName().compareTo(strDate)<=0){
try {
boolean st = file.delete();
boolean dirStatus = dirc.delete();
System.out.println("===st=="+st);
System.out.println("===dirStatus=="+dirStatus);
if(dirc.isDirectory()){
boolean bs = file.delete();
System.out.println("==bs=="+bs);
boolean dircStatus = dirc.delete();
System.out.println("===dircStatus=="+dircStatus);
}
}catch (SecurityException se) {
se.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
protected void onPostExecute(final Boolean success) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (success) {
Toast.makeText(DBClearActivity.this, "Micro SD card has been clear data successful!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(DBClearActivity.this, "Clear data failed", Toast.LENGTH_SHORT).show();
}
Intent i = new Intent(getBaseContext(), DbBackupMainActivity.class);
View vi = SettingActivityGroup.group.getLocalActivityManager().startActivity("SettingScreenActivity", i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
SettingActivityGroup.group.replaceView(vi);
}
}
dirStatus
always return false, but this line return true boolean st = file.delete();
Please help me out...