The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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

Godot version 3.5.1
in Engine by (94 points)

1 Answer

+1 vote

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

by (6,942 points)

Big Thanks for the answer.
Im plyaing with :
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:
maybe someone find it helpful.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.