Searchable spinner crashes my app on multitasking
我正在使用库可搜索微调器,但如果我打开微调器后按Android Home按钮或多任务按钮,应用程序将崩溃并在屏幕上打印:"不幸的是,AppName已停止运行。"
我的碎片活动:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | public class buscadorFragment extends Fragment implements View.OnClickListener { public Button BotonRecargar; public IndeterminateRoadRunner UCargando; public TextView TextoPrueba; public TextView TextoError; private OnFragmentInteractionListener mListener; public SearchableSpinner SpCateg; public SearchableSpinner SpUbic; String[] CategoriasArray = {"Categorias"}; String[] UbicacionesArray ={"Ubicaciones"}; ArrayAdapter<String> CatspinnerAdapter; ArrayAdapter<String> UbicspinnerAdapter; public buscadorFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_buscador, container, false); CatspinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, CategoriasArray); CatspinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); SpCateg.setAdapter(CatspinnerAdapter); CatspinnerAdapter.notifyDataSetChanged(); UbicspinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, UbicacionesArray); UbicspinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); SpUbic.setAdapter(UbicspinnerAdapter); UbicspinnerAdapter.notifyDataSetChanged(); SpCateg.setTitle("Categoría"); SpCateg.setPositiveButton("Cancelar"); SpUbic.setTitle("Ubicación"); SpUbic.setPositiveButton("Cancelar"); return view; } |
我的片段布局:
仅添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="2"> <com.toptoche.searchablespinnerlibrary.SearchableSpinner android:layout_width="match_parent" android:layout_height="45dp" android:layout_weight="1" android:id="@+id/Category_Spinner" /> <com.toptoche.searchablespinnerlibrary.SearchableSpinner android:layout_width="match_parent" android:layout_height="45dp" android:layout_weight="1" android:id="@+id/Ubication_Spinner" /> </LinearLayout> |
号
这里有logcat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 08-31 20:09:21.656 18172-18172/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kreativer.upy, PID: 18172 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.toptoche.searchablespinnerlibrary.SearchableSpinner) at android.os.Parcel.writeSerializable(Parcel.java:1323) at android.os.Parcel.writeValue(Parcel.java:1271) at android.os.Parcel.writeArrayMapInternal(Parcel.java:618) at android.os.Bundle.writeToParcel(Bundle.java:1692) at android.os.Parcel.writeBundle(Parcel.java:643) at android.app.FragmentState.writeToParcel(Fragment.java:133) at android.os.Parcel.writeTypedArray(Parcel.java:1140) at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:373) at android.os.Parcel.writeParcelable(Parcel.java:1292) at android.os.Parcel.writeValue(Parcel.java:1211) at android.os.Parcel.writeArrayMapInternal(Parcel.java:618) at android.os.Bundle.writeToParcel(Bundle.java:1692) at android.os.Parcel.writeBundle(Parcel.java:643) at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2643) at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3252) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5426) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method) Caused by: java.io.NotSerializableException: android.widget.ArrayAdapter at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1366) at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483) at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368) at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076) at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406) at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483) at android.os.Parcel.writeSerializable(Parcel.java:1318) at android.os.Parcel.writeValue(Parcel.java:1271) at android.os.Parcel.writeArrayMapInternal(Parcel.java:618) at android.os.Bundle.writeToParcel(Bundle.java:1692) at android.os.Parcel.writeBundle(Parcel.java:643) at android.app.FragmentState.writeToParcel(Fragment.java:133) at android.os.Parcel.writeTypedArray(Parcel.java:1140) at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:373) at android.os.Parcel.writeParcelable(Parcel.java:1292) at android.os.Parcel.writeValue(Parcel.java:1211) at android.os.Parcel.writeArrayMapInternal(Parcel.java:618) at android.os.Bundle.writeToParcel(Bundle.java:1692) at android.os.Parcel.writeBundle(Parcel.java:643) at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2643) at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3252) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5426) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method) |
只有当旋转器打开时才会崩溃,否则应用程序将继续运行。我是新手,想学习,所以提前谢谢。
看起来这是库的问题,因为其他用户在GitHub上报告了相同的问题。为了解决这个问题,可以在onpause()方法中关闭searchablelistDialog。
所以在
1 2 3 4 5 6 | @Override public void onPause() { super.onPause(); dismiss(); } |