From: Martin Vajnar Date: Sat, 2 May 2015 11:46:43 +0000 (+0200) Subject: shape_android: fix freezes on app restart X-Git-Url: https://rtime.felk.cvut.cz/gitweb/orte.git/commitdiff_plain/ca1896fdd20dfc47a34847152121de8c291eef9f shape_android: fix freezes on app restart When application was exited through 'back' button domain associated with the running instance was destroyed, however the publishers and subscribers registered within that domain were left intact. This caused 'Application Not Responding' to be thrown when user wants to start the application again, because it tries to use handles associated with the now defunct publishers/subscribers. In order to prevent this, we destroy Publisher and Subscriber objects upon invocation of onDestroy() callback method. --- diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java index 11e8bab..05d76ff 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherActivity.java @@ -171,7 +171,13 @@ public class PublisherActivity extends Activity { public void onDestroy() { super.onDestroy(); - + + for (PublisherShape shape : publisherView.shapes) + shape.killMe(); + + for (SubscriberElement element : subscriberView.elements) + element.killMe(); + if (appDomain != null) { appDomain.destroy(); appDomain = null; diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java index daf55ad..212be3f 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/PublisherShape.java @@ -312,7 +312,10 @@ public class PublisherShape extends ShapeDrawable */ public void killMe() { - this.publication.destroy(); + if (this.publication != null) { + this.publication.destroy(); + this.publication = null; + } } /** diff --git a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java index a16326a..6b74f63 100644 --- a/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java +++ b/orte/contrib/shape_android/src/org/ocera/orte/shape_android/SubscriberElement.java @@ -243,4 +243,15 @@ public class SubscriberElement extends SubscriptionCallback this.setShape(); } + /** + * When subscriber is removed, destroy subscription. + * + * @since 1.0 + */ + public void killMe() { + if (this.subscription != null) { + this.subscription.destroy(); + this.subscription = null; + } + } }