D daemon Active Member Licensed User Longtime User Oct 31, 2014 #1 For the Crosswalk library I'm developing, document says that it needs many activity lifecycle events and onDestroy() is MUST, since otherwise it will cause memory leak from the native side of the web engine. Refer: https://crosswalk-project.org/apis/embeddingapidocs/reference/org/xwalk/core/XWalkView.html The document talks about these events: onCreate -> Activity_Create onResume -> Activity_Resume onPause -> Activity_Pause onDestroy onActivityResult onNewIntent I wish to have provision to hook-up code to onDestroy and other events. Older related discussion: http://www.b4x.com/android/forum/threads/implement-ondestroy.20244/
For the Crosswalk library I'm developing, document says that it needs many activity lifecycle events and onDestroy() is MUST, since otherwise it will cause memory leak from the native side of the web engine. Refer: https://crosswalk-project.org/apis/embeddingapidocs/reference/org/xwalk/core/XWalkView.html The document talks about these events: onCreate -> Activity_Create onResume -> Activity_Resume onPause -> Activity_Pause onDestroy onActivityResult onNewIntent I wish to have provision to hook-up code to onDestroy and other events. Older related discussion: http://www.b4x.com/android/forum/threads/implement-ondestroy.20244/
Erel B4X founder Staff member Licensed User Longtime User Oct 31, 2014 #2 onActivityResult and onNewIntent are both handled internally. You can use the #Extends attribute to handle these events in your library: http://www.b4x.com/android/forum/threads/extending-activity-class.40502/#content Last edited: Nov 12, 2014
onActivityResult and onNewIntent are both handled internally. You can use the #Extends attribute to handle these events in your library: http://www.b4x.com/android/forum/threads/extending-activity-class.40502/#content
D daemon Active Member Licensed User Longtime User Nov 12, 2014 #3 I'm using this code to handle onDestroy() event: B4X: public class ActivityLifeCycleEvents extends Activity { @Override public void onDestroy() { super.onDestroy(); try { BA ba = (BA) this.getClass().getField("processBA").get(null); ba.raiseEvent(null, "activity_destroy"); return; } catch (Exception e) { throw new RuntimeException(e); } } } In my application, I added #Extends attribute: B4X: #Region Activity Attributes #FullScreen: False #IncludeTitle: True #Extends: b4a.ActivityLifeCycleEvents #End Region And... B4X: Sub Activity_Destroy Log("Destroy") End Sub Will it work? How do I make activity go through this state? I tried killing the app through Settings->Apps->TestApp->Force stop
I'm using this code to handle onDestroy() event: B4X: public class ActivityLifeCycleEvents extends Activity { @Override public void onDestroy() { super.onDestroy(); try { BA ba = (BA) this.getClass().getField("processBA").get(null); ba.raiseEvent(null, "activity_destroy"); return; } catch (Exception e) { throw new RuntimeException(e); } } } In my application, I added #Extends attribute: B4X: #Region Activity Attributes #FullScreen: False #IncludeTitle: True #Extends: b4a.ActivityLifeCycleEvents #End Region And... B4X: Sub Activity_Destroy Log("Destroy") End Sub Will it work? How do I make activity go through this state? I tried killing the app through Settings->Apps->TestApp->Force stop
Erel B4X founder Staff member Licensed User Longtime User Nov 12, 2014 #4 Add a log message in your Java code to see that it runs. Your code looks correct. OnDestroy is not called when the process is killed (this is why it is mostly useless). Press on the back key to destroy the activity.
Add a log message in your Java code to see that it runs. Your code looks correct. OnDestroy is not called when the process is killed (this is why it is mostly useless). Press on the back key to destroy the activity.
D daemon Active Member Licensed User Longtime User Nov 14, 2014 #5 onDestroy() of my library gets called on pressing back button. I can see log in B4A. Is there any alternative to ba.raiseEvent?
onDestroy() of my library gets called on pressing back button. I can see log in B4A. Is there any alternative to ba.raiseEvent?
Erel B4X founder Staff member Licensed User Longtime User Nov 16, 2014 #6 The event is not raised because the activity is paused at that point. This code will not work. You can try to call destroy from Activity_Create to destroy the previous instance (if such exists).
The event is not raised because the activity is paused at that point. This code will not work. You can try to call destroy from Activity_Create to destroy the previous instance (if such exists).