question

A. T. Stolk avatar image
A. T. Stolk asked

Leak in IAP sample?

In the docs it is stated that the PurchaseObserver should be registered in the onStart() method of the Activity. So in the sample code, we see: public void onStart() { super.onStart(); ButtonClickerObserver buttonClickerObserver = new ButtonClickerObserver(this); PurchasingManager.registerObserver(buttonClickerObserver); } But where is the observer deregistered, and where is it cleaned up? It seems to get created every time the app gains focus, but not destroyed when the app loses focus. Also, the sample code is very big, if compared to the 'getting started' documentation that tells you that you only need to override 2 methods at minimum.
iap
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Dixith@Amazon avatar image
Dixith@Amazon answered
Hi Stolk, The purchasing manager only holds one instance of the observer.  If the activity is kicked out of memory, the reference in the onStart() method is lost.  If the activity is started again, the registration will replace the one held by the Purchasing manager.  It is preferred practice to register the observer in the onStart() method of the Application object, since Applications are ejected less frequently than Activities. Thank you.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.