使用Parcelable将对象从一个android活动传递到另一个

使用Parcelable将对象从一个android活动传递到另一个,第1张

概述我想做这个 class A extends Activity{ private class myClass{ } myClass obj = new myClass(); intent i = new Intent(); Bundle b = new Bundle(); b.putParcelable(Constants.Settings, obj); //I ge 我想做这个
class A extends Activity{   private class myClass{   }   myClass obj = new myClass();  intent i = new Intent();  Bundle b = new Bundle();  b.putParcelable(Constants.Settings,obj); //I get the error The method putParcelable(String,Parcelable) in the type Bundle is not applicable for the arguments (int,A.myClass)  i.setClass(getApplicationContext(),B.class);  startActivity(i);  }

如何使用Parcelable将obj传递活动B?

解决方法 正如错误所暗示的,你需要让你的类(在这种情况下是myClass)实现 Parcelable.如果你看一下 documentation for Bundle,所有putParcelable方法都采用Parcelable或它们的某种形式的集合. (这是有意义的,给定名称.)因此,如果您想使用该方法,您需要将Parcelable实例放入包中…

当然你不必使用putParcelable – 你可以改为实现Serializable并调用putSerializable.

总结

以上是内存溢出为你收集整理的使用Parcelable将对象从一个android活动传递到另一个全部内容,希望文章能够帮你解决使用Parcelable将对象从一个android活动传递到另一个所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134832.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存