在Android应用程序传递了两个类之间的String数组数组、应用程序、两个、Android

2023-09-11 20:24:49 作者:兄弟丶这辈子的情の哥们丶这辈子的义

我是新来的机器人。我不知道如何通过两级之间的字符串数组。我试图意图,通过共享类的字符串数组,但我得到的只有一根弦,就不会显示该字符串的其余部分。我的一些朋友说,使用捆绑就可以访问类的字符串数组,但我不知道如何使用捆绑功能。任何人都可以指导我如何通过字符串数组。

I am new to android. i dont know how to pass string array between two class. I tried Intent, by sharing string array between the class, but i get only one string, the rest of the string will not displayed. Some of my friend said, using Bundle we can access string array between the class, but i dont know how to use the bundle function. can anyone guide me how to pass the string array.

推荐答案

如果您正试图从一个活动发送一个字符串转换成另一本可以在Intent来完成。

If you are trying to send a String-array from one Activity to another this can be done in the Intent.

在ClassA的:

Intent intent = new Intent(this, ClassB);
String[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);

在ClassB的:

public void onCreate() {
  Intent intent = getIntent();
  String[] myStrings = intent.getStringArrayExtra("strings");
}