在Android活动之间传递字符串数组

我在第一个活动-A内有2个字符串数组,现在我需要将两个数组都传递给second_activity-B,我该怎么做?

我知道IntentAndroid中的概念类型,并且已经将单个变量值传递给了另一个活动,但是我还没有实现在活动之间传递字符串数组的概念,因此我已经在网上冲浪了。

请让我知道可能的解决方案。


慕田峪4524236
浏览 615回答 3
3回答

白板的微信

Bundle b=new Bundle();b.putStringArray(key, new String[]{value1, value2});Intent i=new Intent(context, Class);i.putExtras(b);希望这会帮助你。为了阅读:Bundle b=this.getIntent().getExtras();String[] array=b.getStringArray(key);

森林海

这不是直接解决问题的方法,但是您也可以在包中使用.putStringArrayListExtra()。它比发送字符串数组更灵活。Bundle b=new Bundle();b.putStringArrayListExtra("URL_ARRAY_LIST",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myStringArrayList);Intent i=new Intent(context, Class);i.putExtras(b);然后,您可以按以下方式获取此arrayList:ArrayList<String> urls;urls = getIntent().getStringArrayListExtra("URL_ARRAY_LIST");

素胚勾勒不出你

意图将数据携带到键值映射中,其中“键”是在将数据存储到意图中时选择的字符串名称标识符。读取该数据时,您请求相同的“密钥”。您可以在单个Intent中存储各种数据类型。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android