play-billing-samples icon indicating copy to clipboard operation
play-billing-samples copied to clipboard

Store billing client inside Application scope

Open JenyaKirmiza opened this issue 2 years ago • 4 comments

Hi, I would much appreciate if someone help me with this quiestion. I have multiple-activities app, and I'm setting app billing client in each activity which I don't like. And because of this I had some issues when calling endConnection() in onDestroy(), so I just don't call endConnection any longer. Is this possible to keep single instance of bllling client inside Application scope, so that I can reuse it in any activity? What are the pros/cons. I want to move to single activity approach in future and use billing client in single activity, but currently I don't have enough time to rewrite the whole navigation.

JenyaKirmiza avatar Oct 24 '23 19:10 JenyaKirmiza

It would be nice if billing client is mostly handled on google lib side, I mean you can move the logic of starting and ending billing connection to your side, so developers wouldn't worry about it. You can do the same way as Timber, It can be planted on the start of Application.

JenyaKirmiza avatar Oct 25 '23 09:10 JenyaKirmiza

I had good success putting all the billing stuff in its own viewModel when I did it.

Then simply associate the VM with any activity where you want to use it.

I would startConnection in the VM init and endConnection in VM onCleared.

matale avatar Oct 29 '23 19:10 matale

@matale thanks. did you have any memory leaks?

JenyaKirmiza avatar Oct 29 '23 23:10 JenyaKirmiza

@matale thanks. did you have any memory leaks?

I don't think so but also didn't look for them specifically.

matale avatar Nov 04 '23 02:11 matale