当前位置: 首页 > news >正文

网站建设和域名备案搜索引擎关键词优化

网站建设和域名备案,搜索引擎关键词优化,网站数据库名称怎么改,大型门户网站建设多少钱一、前言 这篇文章主要针对Serialiable和Parcelable接口来传递对象。呈现的功能是跳转到另一个界面,然后通过toast展现我收到的数据。 二、使用Serialiable接口传递数据 1.创建需要传递的对象 //必须实现Serializable接口,此对象才有传递的资格 publ…

一、前言

这篇文章主要针对Serialiable和Parcelable接口来传递对象。呈现的功能是跳转到另一个界面,然后通过toast展现我收到的数据。

二、使用Serialiable接口传递数据

1.创建需要传递的对象

//必须实现Serializable接口,此对象才有传递的资格
public class Student implements Serializable {public int id;public String name;public int age;}

2.传数据

   /*** 跳转到Serialiable2Activity* @param view*/public void startActivity(View view) {Intent intent = new Intent(this, Serialiable2Activity.class);//传递对象到Serialiable2ActivityStudent student = new Student();student.id = 9;student.name = "Anglin";student.age = 33;intent.putExtra("student",student);startActivity(intent);}

3.接收数据

Intent intent = getIntent();Student student = (Student) intent.getSerializableExtra("student");//提示显示Toast.makeText(this, "student.id" + student.id +"student.name"+student.name + "student.age" + student.age,Toast.LENGTH_SHORT).show();

二、使用Parcelable接口传递数据

1.创建需要传递的数据对象

//成为Parcelable的子类,就具备传递数据的资格
public class ParcelableStudent implements Parcelable {public ParcelableStudent() {}//我们自己定义的成员public String name;public int age;//TODO 读取的数据和写入的数据一定要一致否则会报错//从Parcel对象里面读出来,赋值给成员//构造函数protected ParcelableStudent(Parcel in) {//这个函数的意义就是从Parcel读取数据赋值给name和agename = in.readString();age = in.readInt();}//把属性写入到Parcel 对象中去@Overridepublic void writeToParcel(@NonNull Parcel parcel, int i) {parcel.writeString(name);parcel.writeInt(age);}//先不管,是系统扩展用的@Overridepublic int describeContents() {return 0;}//静态公开的成员,Parcelable内部会调用。  一定要有 自动生成 或者从文档中复制不需要去写。public static final Creator<ParcelableStudent> CREATOR = new Creator<ParcelableStudent>() {//创建ParcelableStudent对象  并且Parcel对象构建好传递给ParcelableStudent(成员数据就可以从Parcel获取了)@Overridepublic ParcelableStudent createFromParcel(Parcel in) {return new ParcelableStudent(in);}//@Overridepublic ParcelableStudent[] newArray(int size) {return new ParcelableStudent[size];}};
}

2.传送数据

  public void startActivity(View view) {Intent intent = new Intent(this,Parcelable2Activity.class);ParcelableStudent student = new ParcelableStudent();student.age = 20;student.name = "Anglin";intent.putExtra("student",student);startActivity(intent);}

3.接收数据

    Intent intent = getIntent();ParcelableStudent student = intent.getParcelableExtra("student");//显示Parcelable1Activity 传递过来的对象 里面的数据Toast.makeText(this, "student.name" + student.name + "student.age" + student.age, Toast.LENGTH_SHORT).show();

四、总结

那么在编写android代码 的时候这两个我们改选择使用哪个呢?一般我们会选择使用Parcelabe,因为parcelable的性能更高。Serialiable面向jvm使用java序列化的形式传递对象的。android平台的虚拟机更适合Parcelable。

所以android开发必须使用Parcelabe因为这个是支持  兼容安卓虚拟机。我们主推的方式

http://www.mnyf.cn/news/47476.html

相关文章:

  • 手机版网站建设多少钱关键词检测工具
  • html5网站开发的源码推广app佣金平台正规
  • 传奇新开网站传奇三肖seo网络推广知识
  • 做网站 用什么语言企业邮箱
  • nas wordpress建站哈尔滨最新
  • 怎样做禁毒网站的试卷长沙关键词优化方法
  • 南昌网站建设公司渠道seo排名的影响因素有哪些
  • 长沙房产集团网站建设长春seo按天计费
  • 建站软件刚出来的新产品怎么推
  • 装修网站设计需求说明分析下载文档小红书广告投放平台
  • 中森网站建设公司线上营销手段有哪些
  • 做数据分析好看的网站网站宣传方式有哪些
  • 深圳专业商城网站设计河北seo平台
  • 河北中保建设集团网站首页百度认证官网申请
  • 优秀 网站设计 蓝色seo薪酬
  • 网站备案时间20工作日网络推广好做吗
  • 电子商务网站建设内容网络推广公司哪家做得好
  • 济宁亿峰科技做网站一年多少费用cba赛程
  • 如何建设网站济南兴田德润简介电话百度官方网站
  • 揭阳cms建站模板黄山网站seo
  • 做商城网站产品怎么分布怎么弄一个自己的网站
  • 美间在线设计平台长治网站seo
  • 沈阳做网站费用重庆森林电影完整版
  • 网站备案增加域名福州seo视频
  • xml做网站aso关键词覆盖优化
  • 有啥创意可以做商务网站的个人如何做seo推广
  • 嘉兴市城乡规划建设局网站百度网页版网址
  • 国际军事新闻最近新闻手机优化大师官方免费下载
  • 网站关键词优化seo百度竞价教程
  • 网站域名如何管理软文是什么意思