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

Avoid crash on Android 4 by getting a vector icon from the local context instead of the application context. #3247

Merged
merged 1 commit into from
Jul 26, 2019

Conversation

zestyping
Copy link
Contributor

Issues: Closes #3246.
Scope: MapboxMapFragment
Requested reviewers: @lognaturel

User-visible changes

A crash when opening a Mapbox map on Android 4.x is avoided.

Internal changes

I was able to replicate and confirm this crash in an Android 4.x emulator. I was puzzled by this, and don't understand why it's happening.

First, I tried switching to VectorDrawableCompat.create() as recommended by this Stack Overflow post. This did avoid the crash.

But then I went looking and found that there are many places where we call ContextCompat.getDrawable to get a vector icon (e.g. FileArrayAdapter, FormHierarchyActivity), and when I exercised those code paths in my Android 4.4 emulator, they did not crash. There is even a similar call in OsmDroidMapFragment and it does not crash.

Upon closer inspection I found that these other calls did not use getApplicationContext(), but instead got a context from a local Activity or View. So I tried switching MapboxMapFragment to also use the fragment's context instead of the application context, and that seems to work.

I don't understand why it works, though.

@lognaturel
Copy link
Member

🤦🏻‍♀️Looks like some kind of Android bug to me. Thanks for diving in.

@mmarciniak90
Copy link
Contributor

Tested with success

Verified on Android: 4.4, 4.2 - crash does not occur
Verified also on Android 6.0 and 7.0

@opendatakit-bot unlabel "needs testing"
@opendatakit-bot label "behavior verified"

@lognaturel lognaturel merged commit 7f8c8e3 into getodk:master Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes when Geo question tries to open Mapbox on Android 4.x
4 participants