Wednesday, September 5, 2018

Xamarin.Forms app crashes after update

Leave a Comment

I have checked all the questions raised in SO like this and i couldn't find answer to my issue.

We had an app in PlayStore which is developed in Xamarin.Android with code shared with Xamarin.iOS via Shared Project.

Now we are switching to Xamarin.Forms. We have changed , Some UI Login mechanism with AutoLogin based on Token stored in local device.

The app working fine in Devices and Simulators.

We have uploaded our app to playstore. If the user have old version in their device, after update the app crashing after showing splashscreen for few seconds. If we uninstall the old version, it is working fine.

Error in google console:

    java.lang.RuntimeException:  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2955)  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java030)  at android.app.ActivityThread.-wrap11 (Unknown Source)  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)  at android.os.Handler.dispatchMessage (Handler.java:105)  at android.os.Looper.loop (Looper.java:164)  at android.app.ActivityThread.main (ActivityThread.java:6938)  at java.lang.reflect.Method.invoke (Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java27)  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)  Caused by: java.lang.ClassCastException:  at android.app.SharedPreferencesImpl.getLong (SharedPreferencesImpl.java:279)  at md56c96bd185bfbb3ebebdd94ef17444e8f.MainActivity.n_onCreate (Native Method)  at md56c96bd185bfbb3ebebdd94ef17444e8f.MainActivity.onCreate (MainActivity.java1)  at android.app.Activity.performCreate (Activity.java:7174)  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1220)  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2908) 

We are not sure why this is happening. Can any one let me know, why this happening and how to prevent it. Also, is it possible reproduce this issue in VisualStudio?

Thanks

1 Answers

Answers 1

Probably your SharedPreferences parameters have incompatible types. And I didn't found a proof that it could be xamarin.Forms problem. If you look at the source code SharedPreferencesImpl.java to the getLong method you will see the following cast:

Long v = (Long)mMap.get(key); 

This means that on old versions there was parameter with the same name but with type different from Long. You read this parameter in onCreate method of your MainActivity, but parameter type is incompatible.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment