File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
sample/src/main/java/com/cloudinary/android/sample/app Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,13 @@ private void cancelNotification(String requestId) {
135135 }
136136
137137 private boolean sendBroadcast (Resource updatedResource ) {
138- return LocalBroadcastManager .getInstance (this ).sendBroadcast (new Intent (ACTION_RESOURCE_MODIFIED ).putExtra ("resource" , updatedResource ));
138+ // This is called from background threads and the main thread may touch the resource and delete it
139+ // in the meantime (from the activity) - verify it's still around before sending the broadcast
140+ if (updatedResource != null ) {
141+ return LocalBroadcastManager .getInstance (this ).sendBroadcast (new Intent (ACTION_RESOURCE_MODIFIED ).putExtra ("resource" , updatedResource ));
142+ }
143+
144+ return false ;
139145 }
140146
141147 @ Override
@@ -218,15 +224,11 @@ public void run() {
218224 resource = ResourceRepo .getInstance ().resourceFailed (requestId , error .getCode (), error .getDescription ());
219225 }
220226
221- // resource may be deleted if it was cancelled in the activity
222- if (resource != null ) {
223- sendBroadcast (resource );
224- }
225-
227+ sendBroadcast (resource );
226228 }
227229 });
228- cancelNotification (requestId );
229230
231+ cancelNotification (requestId );
230232
231233 int id = idsProvider .incrementAndGet ();
232234 requestIdsToNotificationIds .put (requestId , id );
You can’t perform that action at this time.
0 commit comments