问题描述
我不能通过整数矩阵两种活动之间。这里是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.
putParceble
putSerializable
您可以用这个做的,是有你的类实现要么。
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::: **
LINK1 包括样品code的
LINK2
LINK3
这篇关于传递两个活动之间的数值矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!