简体   繁体   English

通过意图将自定义数组数据传递到另一个活动

[英]Pass Custom array Data to another activity via intent

     final RecipientEditTextView emailRetv =
      (RecipientEditTextView) findViewById(R.id.email_retv);
      emailRetv.setTokenizer(new Rfc822Tokenizer());
       emailRetv.setAdapter(new BaseRecipientAdapter(this));
       DrawableRecipientChips[] chips = phoneRetv.getSortedRecipients();

I need to send DrawableRecipientChips[] chips to another activity via intents. 我需要通过意图将DrawableRecipientChips []芯片发送到另一个活动。 please how do i go about?. 请我怎么去?

DrawableRecipientChips[] chips is from this libary DrawableRecipientChips []芯片来自此

If you have complex objects that you need to pass from one Activity to another, you don't have to put them in the Intent . 如果您有复杂的对象需要从一个Activity传递到另一个Activity ,则不Intent它们放在Intent You can just put them in public static variables, like this: 您可以将它们放在public static变量中,如下所示:

in ActivityA : ActivityA

public static DrawableRecipientChips[] chips;

in ActivityB.onCreate() : ActivityB.onCreate()

// Get reference to the chips array from the previous Activity
chips = ActivityA.chips;

This isn't a perfect solution, because if Android kills your process and the user returns to the app, the public static variable will be null. 这不是一个完美的解决方案,因为如果Android终止了您的进程并且用户返回了应用程序,则public static变量将为null。 But you can test for that case and then restart your app from the beginning if this happens. 但是您可以测试这种情况,然后在发生这种情况时从头开始重新启动应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM