简体   繁体   中英

Listen for PURCHASES_UPDATED for redeem promo codes while my app is running

I'm reading in-app promotions documentation to allow users to redeem promo codes. The docs say we need to cover the case when a user redeems a promo code in Play Store app while our app is running. This is done by listening for PURCHASES_UPDATED intent.

The docs say we have to register the broadcast receiver (for PURCHASES_UPDATED) in activity's onResume() method. And unregister it in onPause().

But, if my app is open, and the user opens Play Store app, my app activity's onPause method will be executed, so the broadcast receiver will be unregistered, and my app won't be notified...

Are the docs incorrect? Or am I missing something?

Several cases may apply here.

First, there are Android devices that can run multiple activities in the foreground, or you may be buying the content on a separate device with the same account. In these cases, your receiver will do just what it's supposed to do.

Second, in the more usual case, yes, you will have a problem and have to check for purchases in onResume() additionally, as your receiver will not fire while the app was closed. Since you should already be checking this in onStart(), because your app wants to know what the pruchased items are on startup, you may want to consider just moving that check.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM