mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-03 13:44:40 +00:00
Check FragmentViewLifecycleOwner
This commit is contained in:
parent
91b3e149d5
commit
3f1c87a563
1 changed files with 25 additions and 0 deletions
|
@ -36,6 +36,7 @@ import androidx.lifecycle.LifecycleService;
|
|||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
@ -243,6 +244,30 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
|
||||
private void deliver() {
|
||||
if ("androidx.fragment.app.FragmentViewLifecycleOwner".equals(owner.getClass().getName()))
|
||||
try {
|
||||
Field mFragment = owner.getClass().getDeclaredField("mFragment");
|
||||
mFragment.setAccessible(true);
|
||||
Fragment fragment = (Fragment) mFragment.get(owner);
|
||||
if (fragment != null) {
|
||||
if (fragment.getActivity() == null) {
|
||||
Log.w("Fragment without activity" +
|
||||
" task=" + name +
|
||||
" fragment=" + fragment.getClass().getName() +
|
||||
" lifecycle=" + owner.getLifecycle().getCurrentState());
|
||||
return;
|
||||
}
|
||||
if (fragment.getContext() == null) {
|
||||
Log.w("Fragment without context" +
|
||||
" task=" + name +
|
||||
" fragment=" + fragment.getClass().getName() +
|
||||
" lifecycle=" + owner.getLifecycle().getCurrentState());
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
try {
|
||||
onPostExecute(args);
|
||||
} catch (Throwable ex) {
|
||||
|
|
Loading…
Reference in a new issue