如何从一个活动传递引用(非序列化)到另一个? [英] How to pass reference (non-serializable) from one Activity to another?

查看:160
本文介绍了如何从一个活动传递引用(非序列化)到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个引用一个对象,我应该如何去通过这个从一个活动到另一个?

Say I have an reference to an object, how should I go about passing this from one Activity to another?

我不希望有查询应用程序对象/单身/静态变量。

I don't want to have to query the Application Object / singletons / static variables.

这仍然是可能的吗?

推荐答案

您可以声明在另一个活动静态变量,或在应用程序类中的一些全局变量,那么它获得的任何活动,比如你想分析的一些对象键入NEWTYPE,上课NewActivity,从OldActivity。做如下:

You can declare a static variable in another activity, or some Global Variable in Application class, then access it to any activity, like you want to parse some Object of Type NewType, to Class NewActivity, from OldActivity. Do as Following:

声明静态NEWTYPE的对象在NewActivity.java。

Declare an Object of Static NewType in NewActivity.java.

public static NewObject newObject=null;

不继,当你调用NewActivity。

do Following, when you invoke NewActivity.

NewActivity.newObject=item;
Intent intent=new Intent(OldActivity.this, NewActivity.class);
startActivity(intent);

这篇关于如何从一个活动传递引用(非序列化)到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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