Kill media tasks

pull/217/head
M66B 8 months ago
parent dd503c8197
commit 3327cde920

@ -357,7 +357,7 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
tvCaption.setVisibility(View.VISIBLE);
ivImage.setImageResource(R.drawable.twotone_warning_24);
}
}.execute(context, owner, args, "media:load");
}.setKill(true).execute(context, owner, args, "media:load");
} else
ivImage.setImageResource(attachment.progress == null
? R.drawable.twotone_image_24 : R.drawable.twotone_hourglass_top_24);

@ -54,6 +54,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
private boolean log = true;
private boolean count = true;
private boolean keepawake = false;
private boolean kill = false;
private String id;
private String name;
@ -104,6 +105,12 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
return this;
}
@NonNull
public SimpleTask<T> setKill(boolean kill) {
this.kill = kill;
return this;
}
@NonNull
public SimpleTask<T> setExecutor(ExecutorService executor) {
this.localExecutor = executor;
@ -447,6 +454,13 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
}
protected void onDestroyed(Bundle args) {
if (this.kill && future != null)
try {
Log.i("Killing task=" + name);
future.cancel(true);
} catch (Throwable ex) {
Log.w(ex);
}
}
@Override

Loading…
Cancel
Save