
更新:
IParcelable显然是cannot currently be implemented in Mono for Android.最后我在类中使用了.NET序列化,然后在特定于AndroID的代码中对序列化数据进行了分区/捆绑,这很好用.它还使类跨平台兼容,这是可取的.
原始问题:
我正在尝试将Parcelable实现为Mono for AndroID应用程序中的一部分,但是Xamarin的Parcelable文档是从AndroID文档中复制粘贴的:
http://androidapi.xamarin.com/?link=T%3aAndroid.OS.IParcelable
public class MyParcelable implements Parcelable { private int mData; public int describeContents() { return 0; } public voID writetoParcel(Parcel out, int flags) { out.writeInt(mData); } public static final Parcelable.Creator<MyParcelable> CREATOR = new Parcelable.Creator<MyParcelable>() { public MyParcelable createFromParcel(Parcel in) { return new MyParcelable(in); } public MyParcelable[] newArray(int size) { return new MyParcelable[size]; } }; private MyParcelable(Parcel in) { mData = in.readInt(); }}由于该文档是为Java编写的,因此对C#来说基本上是错误的.我只是想知道是否有人知道如何将此代码转换为C#.我在CREATOR领域遇到了麻烦.
此外,由于我正在尝试编写可以在以后移植到其他平台的代码,实现Parcelable的最佳方法是什么?我应该使用部分类使其成为课程的一部分吗?
解决方法:
我经常忘记匿名内部类(AIC对我来说)的一件事是,AIC中的“类型”不会直接转换为C# – 它们是接口,这意味着C#的标准是以“I”开头.此外,每个AIC必须在c#中明确实现.
以下是否有帮助?
public class Creator : IParcelableCreator{ public java.lang.Object CreateFromParcel(Parcel source) { throw new NotImplementedException(); } public java.lang.Object[] NewArray(int size) { throw new NotImplementedException(); } public IntPtr Handle { get { throw new NotImplementedException(); } }}然后:
public class MyParcelable : IParcelable{ public int DescribeContents() { throw new NotImplementedException(); } public voID WritetoParcel(Parcel dest, int flags) { throw new NotImplementedException(); } public IntPtr Handle { get { throw new NotImplementedException(); } }} 总结 以上是内存溢出为你收集整理的Mono for Android,Parcelable&C# – 文档错误全部内容,希望文章能够帮你解决Mono for Android,Parcelable&C# – 文档错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)