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
Fix various Lint issues #666
Merged
Merged
Conversation
This file contains 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
- Fix potential memory leak in `Stripe` `AsyncTask`s by making them static inner classes and using `WeakReference` for references to `Activity` - Use `ConfigurationCompat` to get current locale - Use `Locale.ROOT` when calling `String#toUpperCase()`, `String#toLowerCase()`, or `String#format` for constants or non-user visibile strings - Create a valid `@IdRes` for `CardInputWidget.DEFAULT_READER_ID` - Add missing constants to `@StringDef` annotation in `StripeApiHandler` and `Source` - Avoid scientific notation in in vector paths because it can lead to crashes on some devices
mshafrir-stripe
force-pushed
the
mshafrir-fix-issues
branch
from
December 3, 2018 17:50
98c4ed3
to
e1c4ff5
Compare
ksun2-stripe
approved these changes
Dec 19, 2018
mshafrir-stripe
added a commit
that referenced
this pull request
Apr 11, 2019
**Summary** `Stripe` and `CustomerSession` methods accept callback objects that typically hold references to `Activity` objects. The best practice in Android is that references to `Activity` objects should be weakly held for long-running background tasks, because the `Activity` may go away (e.g. user leaves activity before task is complete). The change was first introduced in #666. After this change, users began reporting that callback objects would mysteriously be garbage-collected by the OS. I was able to reproduce this as well, and found a work-around by moving anonymous inline classes to instance variables - see 2b74328. Android will GC objects that are no longer strongly referenced. When inlined, the callback objects were no longer strongly referenced once the method completed (e.g. in 2b74328, the left-side of `AddSourceActivity#onActionSave`); moving these objects to be instance variables meant that they were now strongly-referenced by the Activity. This explains why the GC issues were resolved with this change. In conclusion, the correct solution is to have the callback objects weakly-reference `Activity` objects, rather than weakly-reference the callback objects themselves. **Motivation** ANDROID-340
galkahana
pushed a commit
to khealth/stripe-android
that referenced
this pull request
Apr 15, 2019
…ipe#863) **Summary** `Stripe` and `CustomerSession` methods accept callback objects that typically hold references to `Activity` objects. The best practice in Android is that references to `Activity` objects should be weakly held for long-running background tasks, because the `Activity` may go away (e.g. user leaves activity before task is complete). The change was first introduced in stripe#666. After this change, users began reporting that callback objects would mysteriously be garbage-collected by the OS. I was able to reproduce this as well, and found a work-around by moving anonymous inline classes to instance variables - see 2b74328. Android will GC objects that are no longer strongly referenced. When inlined, the callback objects were no longer strongly referenced once the method completed (e.g. in 2b74328, the left-side of `AddSourceActivity#onActionSave`); moving these objects to be instance variables meant that they were now strongly-referenced by the Activity. This explains why the GC issues were resolved with this change. In conclusion, the correct solution is to have the callback objects weakly-reference `Activity` objects, rather than weakly-reference the callback objects themselves. **Motivation** ANDROID-340
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stripe
AsyncTask
s by making them static inner classes and usingWeakReference
for references toActivity
ConfigurationCompat
to get current localeLocale.ROOT
when callingString#toUpperCase()
,String#toLowerCase()
, orString#format
for constants or non-user visibile strings@IdRes
forCardInputWidget.DEFAULT_READER_ID
@StringDef
annotation inStripeApiHandler
andSource