check for nullable context

stop task on pause

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-09-06 08:20:31 +02:00
parent 572d63e428
commit 5a53ca3c7c
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 21 additions and 6 deletions

View file

@ -87,7 +87,11 @@ public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult
searchRemoteOperation.setLimit(limit);
searchRemoteOperation.setTimestamp(timestamp);
return searchRemoteOperation.execute(account, photoFragment.requireContext());
if (photoFragment.getContext() != null) {
return searchRemoteOperation.execute(account, photoFragment.getContext());
} else {
return new RemoteOperationResult(new IllegalStateException("No context available"));
}
}
}

View file

@ -21,6 +21,7 @@
package com.owncloud.android.ui.fragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -50,12 +51,22 @@ public class PhotoFragment extends OCFileListFragment {
private boolean photoSearchQueryRunning = false;
private boolean photoSearchNoNew = false;
private SearchRemoteOperation searchRemoteOperation;
private AsyncTask photoSearchTask;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onPause() {
super.onPause();
if (photoSearchTask != null) {
photoSearchTask.cancel(true);
}
}
/**
* {@inheritDoc}
*/
@ -138,7 +149,7 @@ public class PhotoFragment extends OCFileListFragment {
private void searchAndDisplay() {
if (!photoSearchQueryRunning && !photoSearchNoNew) {
new PhotoSearchTask(getColumnsCount(),
photoSearchTask = new PhotoSearchTask(getColumnsCount(),
this,
accountManager.getCurrentAccount(),
searchRemoteOperation,