AndroidActivityCallbacks onPause/onResume


#1

I’m following this guide for extending Activity:

https://docs.nativescript.org/runtimes/android/advanced-topics/extend-application-activity#extending-activity

Why are onPause and onResume not included in AndroidActivityCallbacks? My application.on(application.suspendEvent, ...) and application.on(application.resumeEvent, ...) calls no longer work now.

Thanks!


#2

They are included but under a slightly different name, you can use these following activity callbacks within your ngOnInit():

application.android.on(application.AndroidApplication.activityPausedEvent, () => { });
application.android.on(application.AndroidApplication.activityResumedEvent, () => { });
application.android.on(application.AndroidApplication.activityStoppedEvent, () => { });```

#4

I am experiencing the same issues as the OP. While your solution works for Android, it doesn’t work for iOS. Is there a way in making it compatible for both platforms? Using application.on(application.lowMemoryEvent, __) no longer runs


#5

i doubt it, the events used are android events, not ios events


#6

Do you know why the application events are no longer working when we extend the activity?

Doesn’t seem good to have both android specific events (application.android.on(application.AndroidApplication.activityPausedEvent) in addition to the platform independent event provided by nativescript (application.on(application.suspendEvent).


#7

Are you following the instructions here while extending the activity? You will have to trigger callbacks form your extended activity using . _callbacks object.

https://docs.nativescript.org/core-concepts/android-runtime/advanced-topics/extend-application-activity#extending-activity


#8

Yes, my activity.android.ts is a duplicate of the docs. The moment I added this, my application events stopped working, but it will work if I use the activity callbacks mast3rd3mon mentioned.


#9

That’s the right way of doing and just the same described in docs. Android activity life cycle events are under android name space only as it won’t be valid in iOS.