Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - avoid crashing when deleting already deleted region
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed May 8, 2017
1 parent 45545e1 commit 447e2a5
Showing 1 changed file with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class OfflineRegion {
//Region id
private long id;

// delete status
private boolean isDeleted;

private OfflineRegionDefinition definition;

/**
Expand Down Expand Up @@ -205,7 +208,7 @@ private boolean deliverMessages() {

/**
* Constructor
*
* <p>
* For JNI use only, to create a new offline region, use
* {@link OfflineManager#createOfflineRegion} instead.
*/
Expand Down Expand Up @@ -346,28 +349,31 @@ public void run() {
* @param callback the callback to be invoked
*/
public void delete(@NonNull final OfflineRegionDeleteCallback callback) {
deleteOfflineRegion(new OfflineRegionDeleteCallback() {
@Override
public void onDelete() {
getHandler().post(new Runnable() {
@Override
public void run() {
callback.onDelete();
OfflineRegion.this.finalize();
}
});
}
if (!isDeleted) {
deleteOfflineRegion(new OfflineRegionDeleteCallback() {
@Override
public void onDelete() {
isDeleted = true;
getHandler().post(new Runnable() {
@Override
public void run() {
callback.onDelete();
OfflineRegion.this.finalize();
}
});
}

@Override
public void onError(final String error) {
getHandler().post(new Runnable() {
@Override
public void run() {
callback.onError(error);
}
});
}
});
@Override
public void onError(final String error) {
getHandler().post(new Runnable() {
@Override
public void run() {
callback.onError(error);
}
});
}
});
}
}

/**
Expand Down

0 comments on commit 447e2a5

Please sign in to comment.