I made little changes to your code to run it on my pc.
MainActivity.java
textView=findViewById(R.id.textView);
textView.setVisibility(View.INVISIBLE);
//make textView visible
Intent i= getIntent();
String value = i.getStringExtra("buttonStatus");
if (i!=null && value!=null && value.equals("Visible")) {
textView.setVisibility(View.VISIBLE);
}
//button to go to second activity
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i);
}
});
SecondActivity.java
Button create = findViewById(R.id.create);
create.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SecondActivity.this, MainActivity.class);
intent.putExtra("buttonStatus", "Visible");
startActivity(intent);//launch main activity again
}
});
This makes the textView visible in MainActivity.
But if you press back button to go back to MainActivity you will see no change.
When your application starts, the application stack has only MainActivity in it. Lets call it MainActivity1.
Then, you press a button to go to SecondActivity. Your application stack contents are now :- MainActivity1 / SecondActivity
Then when you launch MainActivity again from SecondActivity MainActivity2 get in the stack.
Stack becomes MainActivity1 / SecondActivity / MainActivity2.
Changes are visible in MainActivity2, not in MainActivity1. If you use back button to go back to MainActivity1, textView will still be invisble.
Also note that, MainActivity1 was launched from another intent, and MainActivity2 was launched from different intent in SecondActivity.
Edit:-
If you want changes in your MainActivity1, you need to use startActivity for result. Following code changes will be required:-
MainActivity.java
textView=findViewById(R.id.textView);
textView.setVisibility(View.INVISIBLE);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivityForResult(i,100);
}
});
//outside onCreate
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(data!=null)
{
String value = data.getStringExtra("buttonStatus");
if(value!=null && value.equals("Visible")) {
Log.d("Debug", "i am here.");
textView.setVisibility(View.VISIBLE);
}
}
}
SecondActivity.java
Button create = findViewById(R.id.create);
create.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SecondActivity.this, MainActivity.class);
intent.putExtra("buttonStatus", "Visible");
setResult(RESULT_OK, intent);
finish();
}
});
Read more about this changes here how-to-pass-data-from-2nd-activity-to-1st-activity-when-pressed-back-android