How do I display a new activity when I click the activity button on the Android app?
Also, will it be possible to deliver data between these two activities then?
android android-intent android-activity android-button android-lifecycle
From the onClick method of the button
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", value); //Insert data to transfer CurrentActivity.this.startActivity(myIntent); //Start LiveActivity
Inserting these codes will allow you to run new activities.
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String value = int.getStringExtra("key"); //Data to be forwarded
Then, the onCreate method of the newly launched activity receives the data like the code above.
Oh, don't forget to register for a new activity in the Android manifest file.
<activity android:label="@string/app_name" android:name="NextActivity"/>
© 2024 OneMinuteCode. All rights reserved.