Skip to content

Commit

Permalink
Made requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsligh committed Apr 15, 2024
1 parent 26947c7 commit be701b2
Showing 1 changed file with 1 addition and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,9 @@ public abstract class Requester {

public abstract void startAdRequest();

/**
* This Async task is needed because the networkTask needs to be cancelled / destroyed
* on a background thread or it throws a NetworkOnMainThreadException
**/
private static class DestroyNetworkTaskAsyncTask extends AsyncTask<BaseNetworkTask, Void, Void> {

@Override
protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) {
if (baseNetworkTasks.length > 0) {
if (baseNetworkTasks[0] != null) {
baseNetworkTasks[0].cancel(true);
}
}
return null;
}
}

public void destroy() {
if (networkTask != null) {
if(Looper.getMainLooper().getThread() == Thread.currentThread()) {
new DestroyNetworkTaskAsyncTask().execute(networkTask);
} else {
networkTask.cancel(true);
}
networkTask.cancel(true);
}
networkTask = null;
if (fetchAdIdInfoTask != null) {
Expand Down

0 comments on commit be701b2

Please sign in to comment.