我想编组和解组一个实现Parcelable/来自字节数组的类.我很清楚Parcelable表示不稳定,因此不适用于实例的长期存储.但我有一个用例,我需要序列化一个对象,如果由于内部Android更改而解组失败,它不是一个showstopper.该类已经在实现该Parcelable接口.
给定一个类MyClass implements Parcelable,我如何(ab)使用Parcelable接口进行编组/解组?
我正在尝试构建一个 stackview 小部件,它在滑动时应该显示不同的数据。到目前为止,一切正常,但是当我想接收小部件中单击的卡的索引时,我总是得到一个额外的或“null”的操作。我已经尝试了几种解决方法,但没有一个在我的应用程序中起作用。我还设置了一个全新的应用程序,只是为了使这项工作完全隔离。但在这里我得到了完全相同的行为。
我尝试传递索引的几种解决方法:
我观察到,在生成的 exampleData 列表中的正确位置调用 getViewAt 函数之前,它会被多次调用,位置(p0)为“0”...但我不知道这是否会导致空值在 onReceive 函数中,当单击卡片时。
这是我的编码:
清单.xml
<service android:name=".ExampleWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS">
</service>
Run Code Online (Sandbox Code Playgroud)
组件布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<StackView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/stackview">
</StackView>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#ffffff"
android:textStyle="bold"
android:text="empty"
android:textSize="20sp" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
小部件项条目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Icon"
android:id="@+id/newwidgetentry">
</TextView> …Run Code Online (Sandbox Code Playgroud)