Wish Ability to access other activity lifecycle events (e.g. onDestroy)

daemon

Active Member
Licensed User
Longtime User
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/
 

daemon

Active Member
Licensed User
Longtime User
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
 

daemon

Active Member
Licensed User
Longtime User
onDestroy() of my library gets called on pressing back button. I can see log in B4A.
Is there any alternative to ba.raiseEvent?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…