SearchableSpinner icon indicating copy to clipboard operation
SearchableSpinner copied to clipboard

When the listview dialog is opened and I press the home button, the app crashes. How can I fix that?

Open muhammadimran021 opened this issue 7 years ago • 2 comments

muhammadimran021 avatar Jul 19 '18 11:07 muhammadimran021

I noticed the same issue. Also happens when hitting the "recent apps" button. Interestingly, does not happen on orientation change. The cause (when I encountered it) is thus:

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.toptoche.searchablespinnerlibrary.SearchableSpinner)

which is in turn caused by, in my case:

Caused by: java.io.NotSerializableException: android.widget.ArrayAdapter

So the issue seems to be attempting to serialize the adapter attached to the "Spinner," if said adapter is not serializable. Without changing the source code of the project, the only fixes off the top of my head are:

  • to manually de-allocate your Adapter in onSaveInstanceState, save the contents in some other way (like a static List, perhaps), then restore the Adapter in onRestoreInstanceState.
  • to create your own Serializable Adapter that subclasses SpinnerAdapter, and use that to attach to this.

A pain? Yes, and so I personally will probably look for another solution unless this (and other things) are fixed.

If you simply need a general (no specific details) Searchable Spinner implementation, I also found this one:

https://github.com/michaelprimez/searchablespinner

This one requires (currently) targeting API 21+, however.

VerumCH avatar Aug 09 '18 11:08 VerumCH

I encountered this error in my app, but I solved this by looking at the error. I'll tell you the solution to the problem in short. I was using ArrayAdapter in following way ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.whatever)); to display spinner items, but while initializing ArrayAdapter, you can see I made an unchecked call there, so my app crashed when it was minimized. So what I changed in this code was adding concrete type to the object by modifying it in following way ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.whatever)); Now, as my spinner only contained Strings, I could pass String there, but, depending on the layout you'll be submitting to the spinner(if you're using custom views) you can pass your POJO class there.

vedprakashwagh avatar Nov 06 '18 16:11 vedprakashwagh