传递两个活动之间的数值矩阵 [英] pass matrix of values ​​between two activities

查看:133
本文介绍了传递两个活动之间的数值矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能通过整数矩阵两种活动之间。这里是code:

I can't pass a matrix of integers between two activities. here is the code:


  • 活动答:

  • Activity A:

intent.putExtra(matrix_(序列化)矩阵);

活动B:

Bundle extras = getIntent().getExtras();
matrix =  (int[][]) extras.getSerializable("matrix_");


我希望对你有所帮助。
感谢所有

I hope for your help. Thanks to all

推荐答案

在创建意图的一个对象,你可以采取以下的传递两个活动之间的物体两种方法的优势。

When you are creating an object of intent, you can take advantage of following two methods for passing objects between two activities.

<一个href=\"http://developer.android.com/reference/android/os/Bundle.html#putParcelable%28java.lang.String,%20android.os.Parcelable%29\"相对=nofollow> putParceble

<一个href=\"http://developer.android.com/reference/android/os/Bundle.html#putSerializable%28java.lang.String,%20java.io.Serializable%29\"相对=nofollow> putSerializable

您可以用这个做的,是有你的类实现要么 Parcelable 序列化

What you can do with this, is have your class implement either Parcelable or Serializable.

然后你就可以在整个活动自定义类绕过。我发现这非常有用的。

Then you can pass around your custom classes across activities. I have found this very useful.

下面是code的一个小片段,我使用

Here is a small snippet of code I am using

Matrix matrix  = new Matrix ();
Intent i = new Intent();

Bundle b = new Bundle();
b.putParcelable("CUSTOM_LISTING", matrix  );
i.putExtras(b);
i.setClass(this, NextActivity.class);
startActivity(i);

和新开工活动code会是这样的...

And in newly started activity code will be something like this...

Bundle b = this.getIntent().getExtras();
if(b!=null)
    mCurrentListing = b.getParcelable("CUSTOM_LISTING");

**的链接EDITED ::: **

** EDITED WITH LINKS::: **

<一个href=\"http://groups.google.com/group/android-beginners/browse_thread/thread/676a603928950e24/a898ae5c217318e1\"相对=nofollow> LINK1 包括样品code的

<一个href=\"http://stackoverflow.com/questions/2736389/how-to-pass-object-from-one-activity-to-another-in-android\">LINK2

<一个href=\"http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/\"相对=nofollow> LINK3

这篇关于传递两个活动之间的数值矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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