I use the following code to create some temp files, and wrapped tem as inputsteam to send to client side.
I understand that the temp files can be deleted automatically b
Delete the files in onDestroy
if isChangingConfigurations()
is false
or isFinishing
is true
. Example:
@Override protected void onDestroy() {
super.onDestroy();
if(!isChangingConfigurations()) {
deleteTempFiles(getCacheDir());
}
}
private boolean deleteTempFiles(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
for (File f : files) {
if (f.isDirectory()) {
deleteTempFiles(f);
} else {
f.delete();
}
}
}
}
return file.delete();
}