如何在另一个活动中传递数组字符串 URL?



我的主要活动视频列表显示在我的主屏幕中,我在抽屉中设置了按钮,当我点击url home时,我想在我的主屏幕中显示4个按钮,它可以显示我url home或url_one如何传递这些链接请帮助我。

解释: 在我的主屏幕中,显示home_url我在另一个活动主页按钮,第一个链接,第二个链接和收藏夹按钮中设计了四个按钮。在这里,我调用抽屉中的链接按钮,我想在我的主要活动中附加按钮,当我单击主页按钮时,这些按钮向我显示主页按钮第一个链接第二个链接和收藏夹按钮,该按钮旨在为我提供home_url字符串并向我显示视频列表与其他按钮相同。请帮帮我

public class MainActivity extends AppCompatActivity implementsNavigationView.OnNavigationItemSelectedListener, AbsListView.OnScrollListener {

}

使用Intent。

String message = "hello there";    
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("message", message);
startActivity(intent);

在您要进行的活动中,在这种情况下为下一个活动。

Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");

使用它

TextView textView = (TextView) findViewById(R.id.textView);  
textView.setText(message);

请注意, 捆绑包是 Android 系统中用于组件间通信的关键组件之一。您所要做的就是如何使用将数组放入该捆绑包中。

发送方:

Intent intent1 = new Intent(MainActivity.this, NextActivity.class);
Bundle bundle = new Bundle(); 
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("17 Fake Street");
arrayList.add("Phoney town");
arrayList.add("Makebelieveland");
/* you can add more string values in your arrayList */
bundle.putStringArrayList("myArrayListKey", arrayList);
intent1.putExtra(bundle);
startActivity(intent1);

接收方:

Bundle bundle = getIntent().getExtras(); /* you got the passsed bundle */
ArrayList<String> arrayList = bundle.getStringArray("myArrayListKey");  
/* you got the your passed ArrayList<String> */
/* now you can process your ArrayList<String> which you asked */