How does onMainResume() callback in android plugin works?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By VanDeiMin

How does onMainResume() callback in android plugin works?
It is said “forwarded callbacks you can reimplement, as SDKs often need them”
When it is called?
Where to search in source code for answers?
I suppose there are some under the hood functions inside godot android plugin system but i can’t find them
Im trying implement in-app purchases and cannot find the answer what triggers “onMainResume()” callback. Understanding that will help me make connection-brake resistant in-app system
best regards

:bust_in_silhouette: Reply From: Wakatta

On the Android side of things we’d need to have a much longer discussion than this forum might allow.
But basically Android has an app lifecycle and the on_resume() method is triggered whenever an Activity gains focus

On the Godot side you’d have to use the notification system

func _notification(what):

and if you want to trigger it yourself


You have not specified which plugin you’re specifically using so the above is for general use cases

Big Thanks for the answer.
Im plyaing with :
GitHub - godotengine/godot-google-play-billing at billing-v5
where I got the source code and I’m messing under the hood learning java and android api at the same time. I’m following the code logic and adding small changes for reply 5.1.0 billing library needs. Unfortunately I’m no coder and burn lot of time trying to understand how it works.

Anyway my gradlew build works . I can connect to play store and buy consumables at the moment. Problem showed when connection is lost between buying and consuming product.

I resolved problem temporally adding “queryPurchases()” function on callback from “onMainResume” in the plugin (which is callback Activity#onResume() ).

But I suppose beacuse “queryPurchases” is called async so I have an error : Purchase acknowlegde error: 6: ERROR Server error, please try again. “//purchase_token” after buing product. Which is irrelevant beacuse next line in logcat is “purchase acknowledged” with the same token and product can be consumed with no problem

My lack of understanding what an Activity is and what triggers “onMainResume” function in the plugin is the source of the problem.

Now after reading Your answer and making some experiments i can roughly assume and (over)simplify that from billing plugin perspective Activity “is” my application and my interaction with it. “onMainResume()” triggers everytime I switch apps on the phone or I exit the play store.

Anyway with this knowlegde effective acknowleging purchase after connection error is closer for me.

Big thanks Wakatta

p.s Here are links to godot.plugin
Ok link is impossible. One must search on GitHub.

and Activity:
Activity  |  Android Developers
maybe someone find it helpful.

VanDeiMin | 2023-01-03 02:15