Created
April 18, 2017 17:45
-
-
Save loganj/69070bf969ea57037be83b0757a2f11f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit cb5f051c5ee95e795dedaf3a264062cf75d44b1e | |
Author: Logan Johnson | |
Date: Mon Aug 8 14:41:04 2016 -0400 | |
don't register Transaction in multiple scopes | |
RA-14998 | |
TransactionBundler used to implement both Bundler and PausesAndResumes. | |
In order to correct a lifecycle tangle (obvious from the dual | |
implementation), we separated those two concerns and made Transaction | |
implement PausesAndResumes instead. That change was made in this PR: | |
https://stash.corp.squareup.com/projects/ANDROID/repos/register/pull-requests/10689/overview | |
Unfortunately, a side effect of (or possibly, motivation for) having the | |
TransactionBundler implement PausesAndResumes is that we vend a | |
TransactionBundler instance to each caller. That instance would end up | |
getting registered with an Activity scope, which was safe since each | |
caller would get a new instance-- even though Activity scopes overlap, a | |
single PausesAndResumes instance would only ever be registed with a | |
single scope. | |
By making the Transaction implement PausesAndResumes, we created a | |
problem. Transaction is scoped to the Application, and outlives any | |
Activities. Since Activity lifecycles (and thus scopes) overlap, this | |
meant we would attempt to register the Transaction in an incoming | |
Activity scope (via PauseAndResumeRegistrar) while it was still | |
registered in the outgoing Activity's scope. This caused a pretty | |
popular crash. | |
The fix here is to return to vending a PausesAndResumes object to each | |
caller, so that a separate instance is registered with each Activity | |
scope, avoiding the dual-registration crash. | |
note: The attentive reader will see that it's not actually the | |
PausesAndResumes that gets registered with the Scope. It's another | |
Scoped object that wraps the PausesAndResumes and delegates its | |
equals/hashCode. | |
diff --git a/register/src/main/java/com/squareup/payment/Transaction.java b/register/src/main/java/com/squareup/payment/Transaction.java | |
index fd09de4..1121c5e 100644 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment