westlinkin avatar image
westlinkin asked

Should BasePurchasingObserver registered in all activities?

I did PurchasingManager.registerObserver(PurchasingObserver); in my base activity in onStart, and PurchasingManager.initiateGetUserIdRequest(); in onResume(). so every I open an activity, the observer registered. Is that correct? because sometimes when I open my app, I see the iap thread goes well, then I go into another activity, the iap thread stopped at onGetUserIdResponse(GetUserIdResponse) , and onPurchaseUpdatesResponse never gets called. Even GetUserIdAsyncTask never gets called. @Override public void onGetUserIdResponse(final GetUserIdResponse getUserIdResponse) { Log.v(TAG, "onGetUserIdResponse recieved: Response -" + getUserIdResponse); // Log.v(TAG, "RequestId:" + getUserIdResponse.getRequestId()); Log.v(TAG, "IdRequestStatus:" + getUserIdResponse.getUserIdRequestStatus()); new GetUserIdAsyncTask().execute(getUserIdResponse); } I implement the observer like the sample code.
10 |5000

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

1 Answer

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Westlinking, Thank you for posting. There is no harm of having a single PurchasingObserver at the base activity level and register it in activities onStart(). Having that, you could always call IAP methods to PurchasingManager from a storefront activity and after getting response in observer you should be able to broadcast events to notify the target activity to take UI actions. The problem, you are facing, needs to be more clarified. Did you mean when initiateGetUserIdRequest() is in progress if you switch to another activity, you do not get a callback on onGetUserIdResponse() of the instance of PurchasingObserver's derived class you have implemented in your app? You wrote that GetUserIdAsyncTask() never gets called. Could you check that whether you get callback on onGetUserIdResponse() or not. i.e. the following line is being excecuted or not in your code when the problem occurs? Log.v(TAG, "onGetUserIdResponse recieved: Response -" + getUserIdResponse);
10 |5000

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