mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
check for nullable context
stop task on pause Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
572d63e428
commit
5a53ca3c7c
2 changed files with 21 additions and 6 deletions
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,11 +149,11 @@ public class PhotoFragment extends OCFileListFragment {
|
|||
|
||||
private void searchAndDisplay() {
|
||||
if (!photoSearchQueryRunning && !photoSearchNoNew) {
|
||||
new PhotoSearchTask(getColumnsCount(),
|
||||
this,
|
||||
accountManager.getCurrentAccount(),
|
||||
searchRemoteOperation,
|
||||
mContainerActivity.getStorageManager())
|
||||
photoSearchTask = new PhotoSearchTask(getColumnsCount(),
|
||||
this,
|
||||
accountManager.getCurrentAccount(),
|
||||
searchRemoteOperation,
|
||||
mContainerActivity.getStorageManager())
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue