Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More config change bugs: PurchasesUpdatedListener is stored beyond context lifecycle scope #64

Closed
SUPERCILEX opened this issue Jul 4, 2017 · 0 comments

Comments

@SUPERCILEX
Copy link

SUPERCILEX commented Jul 4, 2017

Inside launchBillingFlow, you guys do this:

ResultReceiver chaseResultReceiver =
        new ResultReceiver(mUiThreadHandler) {
            @Override
            protected void onReceiveResult(int responseCode, Bundle resultData) {
                // Here you guys store the BroadcastManager which in turn stores the PurchasesUpdatedListener
                mBroadcastManager.getListener().onPurchasesUpdated(responseCode, purchases);
            }
        };

Then you guys send that stored PurchasesUpdatedListener to the ProxyBillingActivity to be used as a callback. That doesn't work of course if the client context is changed with a rotation for example. So then what happens is the onPurchasesUpdated method gets called on an old context instance which is a memory leak and can cause crashes in the client app.

My proposed solution would be to use the custom action and BroadcastReceiver setup you guys have going. So basically instead of sending that ResultReceiver to the ProxyBillingActivity, you guys would just send a broadcast:

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE) {
        if (resultCode != RESULT_OK || responseCode != BillingResponse.OK) {
            // ...
            LocalBroadcastManager.getInstance(this).sendBroadcast(...)
        }
    }
}

Mirrored on the Google Issue Tracker: https://issuetracker.google.com/issues/63267470.

SUPERCILEX added a commit to SUPERCILEX/Robot-Scouter that referenced this issue Jul 4, 2017
android/play-billing-samples#64
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
SUPERCILEX added a commit to SUPERCILEX/Robot-Scouter that referenced this issue Jul 4, 2017
- Uses the new Play Billing library which fixes #134
- Removes the ProgressDialog (#116)

Includes workarounds for android/play-billing-samples#63 and android/play-billing-samples#64

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant