parcelable

Type argument is not within its bounds Expected: Parcelable Found: String

烂漫一生 提交于 2020-05-29 09:45:24
问题 I am creating a generic, abstract class like this: abstract class BaseDialogFragment<T: Parcelable> : DialogFragment() Trying to implement this class as class MyDialogFragment : BaseDialogFragment<String>() gives me Type argument is not within its bounds Expected: Parcelable Found: String for the String in BaseDialogFragment<String>() . So, how can I use String as a value for T ? Is my condition T: Parcelable somehow wrong, if I want T to be a parcelable type? 回答1: So, how can I use String as

Type argument is not within its bounds Expected: Parcelable Found: String

痞子三分冷 提交于 2020-05-29 09:44:49
问题 I am creating a generic, abstract class like this: abstract class BaseDialogFragment<T: Parcelable> : DialogFragment() Trying to implement this class as class MyDialogFragment : BaseDialogFragment<String>() gives me Type argument is not within its bounds Expected: Parcelable Found: String for the String in BaseDialogFragment<String>() . So, how can I use String as a value for T ? Is my condition T: Parcelable somehow wrong, if I want T to be a parcelable type? 回答1: So, how can I use String as

Type argument is not within its bounds Expected: Parcelable Found: String

痞子三分冷 提交于 2020-05-29 09:44:35
问题 I am creating a generic, abstract class like this: abstract class BaseDialogFragment<T: Parcelable> : DialogFragment() Trying to implement this class as class MyDialogFragment : BaseDialogFragment<String>() gives me Type argument is not within its bounds Expected: Parcelable Found: String for the String in BaseDialogFragment<String>() . So, how can I use String as a value for T ? Is my condition T: Parcelable somehow wrong, if I want T to be a parcelable type? 回答1: So, how can I use String as

Type argument is not within its bounds Expected: Parcelable Found: String

最后都变了- 提交于 2020-05-29 09:44:17
问题 I am creating a generic, abstract class like this: abstract class BaseDialogFragment<T: Parcelable> : DialogFragment() Trying to implement this class as class MyDialogFragment : BaseDialogFragment<String>() gives me Type argument is not within its bounds Expected: Parcelable Found: String for the String in BaseDialogFragment<String>() . So, how can I use String as a value for T ? Is my condition T: Parcelable somehow wrong, if I want T to be a parcelable type? 回答1: So, how can I use String as

Companion Objects in Kotlin Interfaces

怎甘沉沦 提交于 2020-05-11 04:04:23
问题 I am trying to make a interface Parcelable, as such I need a interface like this interface AB : Parcelable { companion object { val CREATOR : Parcelable.Creator<AB> } } and my two classes A and B looking like data class A (...): Parcelable{ ... companion object { val CREATOR : Parcelable.Creator<AB> = object : Parcelable.Creator<AB> { override fun newArray(size: Int): Array<AB?> { return arrayOfNulls(size) } override fun createFromParcel(parcel: Parcel): AB { return A(parcel) } } } I am

Companion Objects in Kotlin Interfaces

孤街浪徒 提交于 2020-05-11 04:03:50
问题 I am trying to make a interface Parcelable, as such I need a interface like this interface AB : Parcelable { companion object { val CREATOR : Parcelable.Creator<AB> } } and my two classes A and B looking like data class A (...): Parcelable{ ... companion object { val CREATOR : Parcelable.Creator<AB> = object : Parcelable.Creator<AB> { override fun newArray(size: Int): Array<AB?> { return arrayOfNulls(size) } override fun createFromParcel(parcel: Parcel): AB { return A(parcel) } } } I am

Android-Parcelable理解与使用(对象序列化)

試著忘記壹切 提交于 2020-03-10 18:49:21
parcel定义介绍: android提供了一种新的类型:parcel(英文解释:包裹,小包),本类用来封装数据的容器,封装后的数据可以通过Intent或IPC传递,除了基本类型外,只有实现了Parcelable接口的类才能放入parcel中。 parcel一般都用在Binder通信,通过read和write方法进行客户端与服务端的数据传递(通信)。 比如:frameworks层服务端与hardware客户端的Binder通信 reply->writeInt32(getCardReaderSize()); int mid = data.readInt32(); 用来存放parcel数据的是内存(RAM),而不是永远介质(Nand等)。 parcelable定义了把数据写入parcel和从parcel读出数据的接口,一个类的实例,如果需要封装到消息中去,就必须实现这一接口,如果实现了这个接口,该类的实例就是可以“被打包”。 Parcelable的定义: 下面我们看下parcelable的源码: 内容描述接口,没什么作用 public int describeC ontents(); 写入接口函数,用来打包 public void writeToParcel(Parcel dest, int flags); 读取接口

kotlin, how to put HashMap in Parcelable

核能气质少年 提交于 2020-02-28 19:03:20
问题 In a class who implements Parcelable it has a HashMap member. Saw Parcelable has public final void readMap(Map outVal, ClassLoader loader) , but could not find a sample to use it. If do it by flatten the map and write/read one by one accordingly, how to extract from the parcel in the constructor? (got error to build the map from the parcelable, cannot access buildTheMap() before constructor is called ) class CachedData(val type: Int, val name: String, val details: HashMap<String, String) :

kotlin, how to put HashMap in Parcelable

一笑奈何 提交于 2020-02-28 19:01:21
问题 In a class who implements Parcelable it has a HashMap member. Saw Parcelable has public final void readMap(Map outVal, ClassLoader loader) , but could not find a sample to use it. If do it by flatten the map and write/read one by one accordingly, how to extract from the parcel in the constructor? (got error to build the map from the parcelable, cannot access buildTheMap() before constructor is called ) class CachedData(val type: Int, val name: String, val details: HashMap<String, String) :

Overriding onSaveInstanceState

孤者浪人 提交于 2020-02-02 10:59:25
问题 I'm trying to come to grips with the onSaveInstanceState method in class View (not the one in class Activity). That method does return a Parcelable. I derived my own View from ViewGroup and overrode that method to save my own state. But when the state was to be saved I got an exception: java.lang.IllegalStateException: Derived class did not call super.onSaveInstanceState() That is true enough, but simply calling that method doesn't seem enough to me. So how should I do this? If the method