I working an App where In my MainActivity I added Toast message which display highest Loaded events.
e.g: In MainActivity
- Toast.makeText(this, "Load Events" + this.events.size(), Toast.LENGTH_LONG).show();
Now, Next part when above toast message appear on the MainActivity screen it will add that event into SecoendActivity Listview
- How do i add toast message event into second activity listview?
- will Mainactivity to SecondActivity?

Tuhin PaulRank #7 · 71.9K reputationPosted Mar 21, 2023, 9:34 PM EDT
Hello Meggy,
To pass the event data from MainActivity to SecondActivity, you can use an Intent to start the SecondActivity and pass the event data as an extra.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 21, 2023, 9:35 PM EDT
In MainActivity, after displaying the Toast message, add the following code to create an Intent and add the event data as an extra:
Intent intent = new Intent(this, SecondActivity.class); intent.putExtra("event_data", this.events.get(this.events.size()-1)); // add the latest event to the intent as an extra startActivity(intent);This code creates an Intent to start the SecondActivity, and adds the latest event data as an extra with the key "event_data".
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 21, 2023, 9:37 PM EDT
In SecondActivity, you can retrieve this event data from the Intent in the onCreate() method and add it to your ListView adapter. See how you can modify your SecondActivity code to achieve this:
public class SecondActivity extends AppCompatActivity { private ListView listView; private List eventList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); listView = findViewById(R.id.listView); eventList = new ArrayList<>(); // get the event data from the intent String eventData = getIntent().getStringExtra("event_data"); // add the event data to the list eventList.add(eventData); // create and set the adapter for the list view ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, eventList); listView.setAdapter(adapter); } }This code retrieves the event data from the Intent in the onCreate() method using the key "event_data", adds it to the eventList list, and creates an ArrayAdapter with this list to set the adapter for the ListView.