Repository navigation
TabView with ScrollView and MapView crashes #3960
Description
Which platform(s) does your issue occur on?
Only tested on Android.
Please provide the following version numbers that your issue occurs with:
- CLI: 2.5.4
- Cross-platform modules: 2.5.2
- Runtime(s): 2.5.0
- Plugin(s): nativescript-google-maps-sdk 1.4.3
Please tell us how to recreate the issue in as much detail as possible.
I have a TabView with three tabs: the first one with a ScrollView, the second one with a MapView, and the third one empty. When the application is first launched it works fine, but if I minimize it and then resume, it crashes as soon as I switch between the tabs.
Sample code: https://github.com/ludcila/tabview-scrollview-mapview
(set API key in app/App_Resources/Android/values/nativescript_google_maps_api.xml)
D/AndroidRuntime(15596): Shutting down VM
W/dalvikvm(15596): threadid=1: thread exiting with uncaught exception (group=0x41f35700)
D/dalvikvm(15596): GC_FOR_ALLOC freed 1595K, 23% free 14306K/18456K, paused 22ms, total 22ms
W/System.err(15596): com.tns.NativeScriptException:
W/System.err(15596): Calling js method instantiateItem failed
W/System.err(15596): Error: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to org.nativescript.widgets.HorizontalScrollView$SavedState
W/System.err(15596): org.nativescript.widgets.VerticalScrollView.onRestoreInstanceState(VerticalScrollView.java:166)
W/System.err(15596): android.view.View.dispatchRestoreInstanceState(View.java:13188)
W/System.err(15596): android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2850)
W/System.err(15596): android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2856)
W/System.err(15596): android.view.View.restoreHierarchyState(View.java:13166)
W/System.err(15596): com.tns.Runtime.callJSMethodNative(Native Method)
W/System.err(15596): com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
W/System.err(15596): com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
W/System.err(15596): com.tns.Runtime.callJSMethod(Runtime.java:1047)
W/System.err(15596): com.tns.Runtime.callJSMethod(Runtime.java:1028)
W/System.err(15596): com.tns.Runtime.callJSMethod(Runtime.java:1018)
W/System.err(15596): com.tns.gen.android.support.v4.view.PagerAdapter_frnal_ts_helpers_l58_c38__PagerAdapterClassInner.instantiateItem(android.support.v4.view.PagerAdapter.java)
W/System.err(15596): android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1001)
W/System.err(15596): android.support.v4.view.ViewPager.populate(ViewPager.java:1183)
W/System.err(15596): android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:666)
W/System.err(15596): android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:628)
W/System.err(15596): android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:609)
W/System.err(15596): org.nativescript.widgets.TabLayout$TabClickListener.onClick(TabLayout.java:406)
W/System.err(15596): android.view.View.performClick(View.java:4475)
W/System.err(15596): android.view.View$PerformClick.run(View.java:18786)
W/System.err(15596): android.os.Handler.handleCallback(Handler.java:730)
W/System.err(15596): android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err(15596): android.os.Looper.loop(Looper.java:137)
W/System.err(15596): android.app.ActivityThread.main(ActivityThread.java:5419)
W/System.err(15596): java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(15596): java.lang.reflect.Method.invoke(Method.java:525)
W/System.err(15596): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
W/System.err(15596): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
W/System.err(15596): dalvik.system.NativeStart.main(Native Method)
W/System.err(15596): File: "file:///data/data/org.nativescript.tabs/files/app/tns_modules/tns-core-modules/ui/tab-view/tab-view.js, line: 64, column: 38
W/System.err(15596): StackTrace:
W/System.err(15596): Frame: function:'PagerAdapterClassInner.instantiateItem', file:'file:///data/data/org.nativescript.tabs/files/app/tns_modules/tns-core-modules/ui/tab-view/tab-view.js', line: 64, column: 39
W/System.err(15596): at com.tns.Runtime.callJSMethodNative(Native Method)
W/System.err(15596): at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
W/System.err(15596): at com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
W/System.err(15596): at com.tns.Runtime.callJSMethod(Runtime.java:1047)
W/System.err(15596): at com.tns.Runtime.callJSMethod(Runtime.java:1028)
W/System.err(15596): at com.tns.Runtime.callJSMethod(Runtime.java:1018)
W/System.err(15596): at com.tns.gen.android.support.v4.view.PagerAdapter_frnal_ts_helpers_l58_c38__PagerAdapterClassInner.instantiateItem(android.support.v4.view.PagerAdapter.java)
W/System.err(15596): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1001)
W/System.err(15596): at android.support.v4.view.ViewPager.populate(ViewPager.java:1183)
W/System.err(15596): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:666)
W/System.err(15596): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:628)
W/System.err(15596): at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:609)
W/System.err(15596): at org.nativescript.widgets.TabLayout$TabClickListener.onClick(TabLayout.java:406)
W/System.err(15596): at android.view.View.performClick(View.java:4475)
W/System.err(15596): at android.view.View$PerformClick.run(View.java:18786)
W/System.err(15596): at android.os.Handler.handleCallback(Handler.java:730)
W/System.err(15596): at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err(15596): at android.os.Looper.loop(Looper.java:137)
W/System.err(15596): at android.app.ActivityThread.main(ActivityThread.java:5419)
W/System.err(15596): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(15596): at java.lang.reflect.Method.invoke(Method.java:525)
W/System.err(15596): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
W/System.err(15596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
W/System.err(15596): at dalvik.system.NativeStart.main(Native Method)
W/System.err(15596): Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to org.nativescript.widgets.HorizontalScrollView$SavedState
W/System.err(15596): at org.nativescript.widgets.VerticalScrollView.onRestoreInstanceState(VerticalScrollView.java:166)
W/System.err(15596): at android.view.View.dispatchRestoreInstanceState(View.java:13188)
W/System.err(15596): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2850)
W/System.err(15596): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2856)
W/System.err(15596): at android.view.View.restoreHierarchyState(View.java:13166)
W/System.err(15596): ... 24 more
I/Process (15596): Sending signal. PID: 15596 SIG: 9
Activity
NickIliev commentedon Apr 10, 2017
Hey, @ludcila thanks for the test project!
The issue is fully reproducible with all API levels using this sample
Steps to reproduce:
randy-johnson commentedon May 7, 2017
I get just about the same error when using the back button on Android when the page going back to is with the mapView and Listview
NickIliev commentedon May 9, 2017
This issue is fixed in NativeScript 3.0.0
Test application with modules 3.0.0 here
12 remaining items
manojdcoder commentedon Aug 14, 2017
@tsonevn Can you please re-open this issue or create new one?
vakrilov commentedon Aug 21, 2017
Reopening the issue - repro project in this comment.
hshristov commentedon Aug 24, 2017
It seems that Google MapView internally sets ids that are not unique and collide with id of our widgets. Once widgets save their state in order to later restore it their state get overridden by the internal widgets of MapView. So in order to prevent this crash you should call in
createNativeView:This will disable state saving for MapView and will stop this crash. After that another crash will happen but it is caused by the plugin itself -
Markerclass changes itsandroidproperty and later when activity is recreated a crash will happen when.addMarkermethod is called. This needs refactoring inside the plugin code in order to be fixed.If you want so save/restore map state it will be possible to attach handler to
applicationlaunchevent and get thesaveInstanceStatebundle from the event args (after this PR is merged #4750).Then in
onActivitySaveInstanceStateyou can save the map state like that:and in application.launch handler to extract the bundle:
and finally in
createNativeViewyou will be able to pass the bundle tocreatemethod:And the plugin author should not update camera position always because this will break state restoration.
shiv19 commentedon Sep 15, 2017
Hey!
I have a workaround for people who are facing crashes with the map view
https://shiv19.github.io/how-to-fix-nativescript-google-maps-sdk-map-view-crash-inside-scroll-view/
Hope this helps someone 😄
lock commentedon Aug 27, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.