fix nullptr crash on killing asyncs

This commit is contained in:
akaessens 2020-09-26 23:00:23 +02:00
parent 5e7d9bc4dc
commit 2e1b20051a
2 changed files with 11 additions and 4 deletions

View File

@ -131,10 +131,15 @@ public class FbScraper {
* cancel vestigial async tasks * cancel vestigial async tasks
*/ */
void killAllTasks() { void killAllTasks() {
try {
for (AsyncTask task : tasks) { for (AsyncTask task : tasks) {
task.cancel(true); task.cancel(true);
task = null; task = null;
} }
} catch (Exception e) {
e.printStackTrace();
}
} }
void scrapePage(String page_url) { void scrapePage(String page_url) {

View File

@ -172,7 +172,9 @@ public class MainActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
input_helper(getString(R.string.helper_add_link), true); input_helper(getString(R.string.helper_add_link), true);
edit_text_uri_input.setText(null); edit_text_uri_input.setText(null);
if (scraper != null) {
scraper.killAllTasks(); scraper.killAllTasks();
}
input_helper(getString(R.string.helper_add_link), false); input_helper(getString(R.string.helper_add_link), false);
} }
}; };