ground-android
ground-android copied to clipboard
OfflineBaseMaps: Exception android.os.NetworkOnMainThreadException
Apparently we're executing network instructions on the main thread. Weirdly enough, this exception never occurred when I committed the recent networking changes to offline basemaps...but now it does.
When I attempt to fix this issue by setting the stream to the IO thread, I get the following exception instead:
com.google.maps.api.android.lib6.common.apiexception.c: Not on the main thread
I'm guessing this might have something to do with the recent changes to the map? I think what's happening is the following:
RX stream 1 (offline basemap repo) --> pulls down network sources, has to run on background thread RX stream 2 (transform of stream 1) --> renders geoJson on map, has to run on main thread.
In theory calling subscribeOn(schedulers.io) and then observeOn(schedulers.ui) should fix the issue--it does workaround the exception, but it doesn't actually make the functionality work, and basemap imagery seems to be completely broken.
RX stream 1 (offline basemap repo) --> pulls down network sources, has to run on background thread
Is this done when creating the TileProvider, or when rendering?
RX stream 2 (transform of stream 1) --> renders geoJson on map, has to run on main thread.
If the stream is transformed into LiveData it will automatically be observed on the UI thread.
RX stream 1 (offline basemap repo) --> pulls down network sources, has to run on background thread
The stream originates in the repository and is called on instantiation of the map in the selector UI. We fetch web tiles and render them so the user can see what they are going to download. It's called onMapReady. Once the webtiles are fetched, the list of urls is passed to the map to create tile providers.
If the stream is transformed into LiveData it will automatically be observed on the UI thread.
ah ok, maybe that will work!
RX stream 1 (offline basemap repo) --> pulls down network sources, has to run on background thread
The stream originates in the repository and is called on instantiation of the map in the selector UI. We fetch web tiles and render them so the user can see what they are going to download. It's called onMapReady. Once the webtiles are fetched, the list of urls is passed to the map to create tile providers.
I see.. I don't understand threading in Maps SDK enough to know what would happen if you ran an async operation in a different thread in onMapReady.. I assume it would just work, but maybe there are some limitations on what can be done there? What happens if you hardcode a a few URLs instead?
If the stream is transformed into LiveData it will automatically be observed on the UI thread.
ah ok, maybe that will work!
Cool, lmk!
@scolsen For your attention when updating the offline basemaps functionality.