MVVMCross Binding Crashes Android Application

后端 未结 2 1142
慢半拍i
慢半拍i 2021-01-22 08:56

I have an Android App based on Xamarin and MvvmCross. In that application there is a view with an ExpandableListView that I created on my own. Now this list displays several ite

2条回答
  •  情歌与酒
    2021-01-22 09:23

    Thanks stuart, but onestly I only pasted some of the code I wrote as my listadapter has become quite complex yet. So actually I already was recycling the controls that I created in code. However it seems I found the solution. I watched my app crashes lately and they all seemed to be because some binding calls the setter of an android widget (EditText, Spinner, Checkbox, etc.) which resulted in a native error. So I placed trace messages into the "Dispose" and "JavaFinalize" methods and as it turns out, the error always happened after some "JavaFinalize" calls. So what I did was to add the following code to all the controls, that I implemented as a "Bindable"something. (like the BindableEditText in the snippet above)

        protected override void JavaFinalize()
        {
            if (this.BindingContext != null)
                this.BindingContext.ClearAllBindings();
            base.JavaFinalize();
        }
    

    So that totally does the job!

    WARNING: I also had to add this to the "MvxListItemView". So maybe it should be added to the mvvmcross sources as well?

提交回复
热议问题