alexrainman / CarouselView

CarouselView control for Xamarin Forms
MIT License
436 stars 176 forks source link

Android Crash when calling OnRestoreInstanceState #15

Closed Pimsch closed 7 years ago

Pimsch commented 8 years ago

First of all thank you for providing this great control. It looks really good.

The problem: The App (Android) crashes when OnRestoreInstanceState is called in the Android Activity with the following error : "Java.Lang.RuntimeException: Parcel android.os.Parcel@XXXXXXX: Unmarshalling unknown type code XXXXXXX at offset XXX"

After some testing i found out that two properties are added to the Bundle that is supposed to be restored in the method call when using the CarouselView:

FragmentPager.SavedState CirclePageIndicator_SavedState

These might be a good start to look.

Thank you for looking into this issue.

alexrainman commented 8 years ago

Will take a look. Thanks for your support.

alexrainman commented 8 years ago

I am not using FragmentPager. I wonder why the property is added to the bundle. Anyway, i am implementing SaveState.

alexrainman commented 8 years ago

@Pimsch i am sorry for the delay. I have been busy. I will solve this soon. Thanks.

alexrainman commented 8 years ago

@Pimsch you may also may check my Google Analytics plugin for Xamarin https://github.com/alexrainman/GAXamarin

Pimsch commented 8 years ago

@alexrainman Thank you for your updates. I will look into your Google Analytics plugin too and present it to my bosses.

Also i have a stackoverflow link i found while testing that might help you. http://stackoverflow.com/questions/26085425/xamarin-android-unfortunately-app-has-stopped This seems to be a similiar issue and the CirclePageIndicator from Xamarin are mentioned as problematic in the comments.

alexrainman commented 8 years ago

I applied the fix to CirclePageIndicator but, i also need to apply a fix to PageAdapter. I have a really cool functionality on my roadmap: SwipeLeftToLoadMore and SwipeRightToRefresh :)

alexrainman commented 8 years ago

I believe i fixed the problem. Can i send you a NuGet package so you can test?

Pimsch commented 8 years ago

Sorry for the late reply i was pretty buisy the last few days. It would be great if you can send me that NuGet package so i can test your fix. What kind of information do you need for that?

alexrainman commented 8 years ago

I will leave you a NuGet package link. Install from a local folder https://developer.xamarin.com/guides/cross-platform/xamarin-studio/nuget_walkthrough/#Adding_Package_Sources and let me know how testing goes. Some small changes in this release. I am deprecating all custom controls except CVLabel as im providing the default HeightRequest per-platform, and im also deprecating PageIndicatorBackgroundColor as i believe is not useful and it helps me to clean up the code.

alexrainman commented 8 years ago

Download from here: https://drive.google.com/file/d/0B6hZDQudMRBUUXE5QVNneVZTbUE/view?usp=sharing

alexrainman commented 8 years ago

@Pimsch did you have any chances to test?

Pimsch commented 8 years ago

@alexrainman Sorry again for the late reply, I just had the chance to test your new package and sadly it did not resolve my issue. Hopefully i can provide you with more information tomorrow when i have a chance to look into this a bit more.

alexrainman commented 8 years ago

@Pimsch it seems u have busy. I will do my own test from my side. Thanks

alexrainman commented 8 years ago

@Pimsch after some testing, what i did for saving state of ViewPager and PageIndicators works but, RestoreState on both of them is not called unless you call RestoreSate in the activity itself.

The solution is to call to onSaveInstanceState and onRestoreInstanceState from the root Activity containing the ViewPager and store the custom view's state programatically as well.

Inside your root Activity implement the following:

Save the state of your custom view

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putParcelable("STATE_COLLECTION", collectionFrameLayout.onSaveInstanceState());
    super.onSaveInstanceState(outState);
}

And inside the onCreate() restore it after you create your custom views.

 if (savedInstanceState != null) {
     Parcelable state = savedInstanceState.getParcelable("STATE_COLLECTION");
     if (state != null) {
         collectionFrameLayout.onRestoreInstanceState(state);
     }
 }

Now, there's a problem, XForms activity doesn't allow you to implement onSaveInstanceState :(

alexrainman commented 7 years ago

If my work is helping you, please help me back: https://xamarinhq.wufoo.com/forms/nominate-a-xamarin-mvp/

alexrainman commented 7 years ago

This is what i have done that is community visible: