Android:将对象从一个活动发送到另一活动 [英] Android: Sending an object from one activity to other activity

查看:73
本文介绍了Android:将对象从一个活动发送到另一活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要将任何对象的意图从一个活动发送到另一个活动,我们可以使用Parcelable Interface或Serializable Interface.两者有什么区别?最好使用哪一个?

To send intent with any object from one activity to another activity we can use Parcelable Interface or Serializable Interface. What is the difference between two? Which one is preferable to use?

此外,我们可以发送字符串,整数类型的对象,而无需使用所有此接口.怎么可能?

Moreover, we can send string, integer type of object without using all this Interface. How it is possible?

推荐答案

可序列化的Java:可序列化来自标准Java,要实现它要容易得多,只需实现可序列化接口并添加重写两个方法即可.

Java Serializable: Serializable comes from standard Java and is much easier to implement all you need to do is implement the Serializable interface and add override two methods.

  private void writeObject(java.io.ObjectOutputStream out)
              throws IOException 
  private void readObject(java.io.ObjectInputStream in)
              throws IOException, ClassNotFoundException

Serializable的问题是它试图适当地处理阳光下的所有事物,并使用大量反射来确定要序列化的类型.因此它成为了一个强大的对象

The problem with Serializable is that it tries to appropriately handle everything under the sun and uses a lot reflection to make determine the types that are being serialized. So it becomes a beefy Object

可打包的Android :Android进程间通信(AIPC)文件,用于告诉Android应该如何对对象进行编组和解组.它的通用性较低,并且不使用反射,因此开销要少得多,并且要快得多.

Androids Parcelable: Android Inter-Process Communication (AIPC) file to tell Android how is should marshal and unmarshal your object.It is less generic and doesn't use reflection so it should have much less overhead and be a lot faster.

这篇关于Android:将对象从一个活动发送到另一活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆