简体   繁体   中英

how can i pass array string url in another activity?

My main activity the video list are shown in my main screen and I set the buttons in drawer, I want to display 4 button in my main screen when i click on url home which can display me url home or url_one how i can pass these links please help me out .

explanation: in my main screen the home_url are displayed i design four buttons in another activity home button, 1st link,2nd link and favorit button. here i call the links in drawer button i want to attach the buttons in my main activity that show me home button 1st link 2nd link and favorit button when i click on home button that intent me the home_url string and display me the video list same as for other buttons. please help me out

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



}

using Intent.

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

In the activity you are going to, NextActivity in this case.

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

To use it

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

Please note, bundle is one of the key components in Android system that is used for inter-component communications . All you have to think is how you can use put your Array inside that bundle.

Sending side:

        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);

Receiving side:

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 */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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