Fixes issue in jobs when context not ready

This commit is contained in:
stom79 2018-01-07 08:36:22 +01:00
parent c20c59b26f
commit 57cd1d8cb4
2 changed files with 7 additions and 3 deletions

View File

@ -130,7 +130,9 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
editor.apply();
}
}
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account, max_id, HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
//noinspection ConstantConditions
if( getContext() != null)
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account, max_id, HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}

View File

@ -126,7 +126,9 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
return;
//Retrieve users in db that owner has.
for (Account account: accounts) {
new RetrieveNotificationsAsyncTask(getContext(), false, account, null, NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
//noinspection ConstantConditions
if( getContext() != null)
new RetrieveNotificationsAsyncTask(getContext(), false, account, null, NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
@ -136,7 +138,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
@Override
public void onRetrieveNotifications(APIResponse apiResponse, final Account account, boolean refreshData) {
List<Notification> notificationsReceived = apiResponse.getNotifications();
if( apiResponse.getError() != null || notificationsReceived == null || notificationsReceived.size() == 0)
if( apiResponse.getError() != null || notificationsReceived == null || notificationsReceived.size() == 0 || account == null)
return;
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);