Question: I need help with my android studio app. When a button is clicked a textView changes to You Clicked the button! There is a second

 I need help with my android studio app. When a button

is clicked a textView changes to You Clicked the button! There is

a second button that when clicked opens a second activity with another

I need help with my android studio app. When a button is clicked a textView changes to You Clicked the button! There is a second button that when clicked opens a second activity with another TextView. The app is supposed to pass the text of the first TextView to the one in the second activity, but I cant figure this out without crashing my code. How do I pass data from one cavity to the other?

patActivity aimed as to be public class MainActivity extends AppCompatActivity { TextView tv; //declaring a TextView variable named as tv Button button, b2; //declaring a Button variable named as btn @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv=findViewById(R.id.tv); button=findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tv.setText("You have clicked the button"); }); b2 = findViewById(R.id.button2); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openActivity2(); public void openActivity2() { Intent intent = new Intent( packageContext: this, MainActivity.class); startActivity (intent); @Override public void onSaveInstanceState(@NonNull Bundle outState, NonNull PersistableBundle outPersistentState) { super.onSaveInstanceState(outState, out PersistentState); outState.putString("key", tv.getText().toString(); public class Main Activity extends AppCompatActivity { TextView tv2; String string; 14 of @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); Intent intent = getIntent(); tv2=findViewById(R.id.textView2); string = savedInstanceState.getString(key: "key"); tv2.setText(string)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!