Stop progress updates when in background
This commit is contained in:
parent
7c43b91502
commit
767f1a6866
@ -210,9 +210,20 @@ public class AppDetails extends ListActivity {
|
||||
reset();
|
||||
viewResetRequired = false;
|
||||
}
|
||||
if (download != null && downloadHandler != null) {
|
||||
downloadHandler.startUpdates();
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (downloadHandler != null) {
|
||||
downloadHandler.stopUpdates();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
db.close();
|
||||
@ -243,7 +254,7 @@ public class AppDetails extends ListActivity {
|
||||
// there.
|
||||
private void copyState(AppDetails old) {
|
||||
download = old.download;
|
||||
if (download != null && download.isAlive()) {
|
||||
if (download != null) {
|
||||
downloadHandler = new DownloadHandler();
|
||||
}
|
||||
ApkListAdapter oldAdapter = (ApkListAdapter)old.getListAdapter();
|
||||
@ -435,8 +446,8 @@ public class AppDetails extends ListActivity {
|
||||
alert.show();
|
||||
return;
|
||||
}
|
||||
downloadHandler = new DownloadHandler();
|
||||
download = new Downloader(curapk);
|
||||
downloadHandler = new DownloadHandler();
|
||||
download.start();
|
||||
}
|
||||
|
||||
@ -490,9 +501,10 @@ public class AppDetails extends ListActivity {
|
||||
// Handler used to update the progress dialog while downloading.
|
||||
private class DownloadHandler extends Handler {
|
||||
private ProgressDialog pd;
|
||||
boolean updating;
|
||||
|
||||
public DownloadHandler() {
|
||||
sendEmptyMessage(0); // Start updating progress
|
||||
startUpdates();
|
||||
}
|
||||
|
||||
public boolean updateProgress() {
|
||||
@ -532,6 +544,18 @@ public class AppDetails extends ListActivity {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void startUpdates() {
|
||||
if (!updating) {
|
||||
updating = true;
|
||||
sendEmptyMessage(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdates() {
|
||||
updating = false;
|
||||
removeMessages(0);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
// The dialog can't be dismissed when it's not displayed,
|
||||
// so do it when the activity is being destroyed.
|
||||
@ -541,7 +565,7 @@ public class AppDetails extends ListActivity {
|
||||
}
|
||||
// Cancel any scheduled updates so that we don't
|
||||
// accidentally recreate the progress dialog.
|
||||
removeMessages(0);
|
||||
stopUpdates();
|
||||
}
|
||||
|
||||
// Repeatedly run updateProgress() until it's finished.
|
||||
@ -566,6 +590,7 @@ public class AppDetails extends ListActivity {
|
||||
File file = new File(download.localFile());
|
||||
Log.d("FDroid", "Cleaning up: " + file);
|
||||
file.delete();
|
||||
download = null;
|
||||
}
|
||||
viewResetRequired = true;
|
||||
break;
|
||||
|
@ -205,6 +205,7 @@ public class Downloader extends Thread {
|
||||
synchronized (this) {
|
||||
status = Status.DONE;
|
||||
}
|
||||
Log.d("FDroid", "Download finished: " + apk_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user