Can anybody say why is this freezing the UI thread?
new Thread(new Runnable() {
@Override
public void run() {
try {
if (!downloadingdemo) {
if (downloadlink.indexOf(".zip") > -1) {
File zipped = new File(context.getExternalFilesDir(context.getFilesDir().getAbsolutePath()).getAbsolutePath() + "/cctemp/books/" + bookid.toString() + ".czfile");
ZipFile zipFile = new ZipFile(zipped);
try {
//File src = new File(basedownloadlocation + bookid + ".czfile");
//zipFile = new ZipFile(src);
if (zipFile.isEncrypted()) {
zipFile.setPassword("www.comic-city.ir");
}
} catch (ZipException e1) {
e1.printStackTrace();
}
File f = new File(basedownloadlocation + bookid);
if (f.exists()) {
for (int i = 0; i < f.listFiles().length; i++) {
File[] lists = f.listFiles();
File fs = lists[0];
fs.delete();
}
f.delete();
}
f.mkdir();
zipFile.extractAll(basedownloadlocation + bookid);
File f1 = new File(basedownloadlocation + bookid + ".czfile");
if (f1.exists()) {
File f2 = new File(basedownloadlocation + bookid);
if (f2.exists()) {
for (int i = 0; i < f2.listFiles().length; i++) {
File f3 = new File(basedownloadlocation + bookid + ".cdfile");
if (f3.exists())
f3.delete();
File[] files = f2.listFiles();
File extractedfile = files[0];
extractedfile.renameTo(new File(basedownloadlocation + bookid + ".cdfile"));
}
f2.delete();
f1.delete();
Encryption.EncryptComic(basedownloadlocation + bookid + ".cdfile", basedownloadlocation + bookid + ".cfile");
//File_Encryption.EncryptFile(basedownloadlocation + bookid + ".cefile", basedownloadlocation + bookid + ".cfile");
File f4 = new File(basedownloadlocation + bookid + ".cdfile");
f4.delete();
}
}
} else {
File f = new File(basedownloadlocation + bookid + ".czfile");
f.renameTo(new File(basedownloadlocation + bookid + ".cfile"));
}
}
}catch(Exception e){}
}).run();
Every line works fine, it just freezes UI. The lines zipFile.extractAll()
and Encryption.EcnryptComic()
takes some time to do their jobs, and I'm using a new thread to prevent UI freeze, but it still freezes the UI for some reason.
This block of code is in a non-activity class that is being called from inside an AsyncTask from inside of an activity.
I've also tried to use AsyncTask instead of threads, and that one does not even do anything (no I have not forgot to execute it.)
So any idea what's wrong with this code?