I have a very simple problem. I have a invisible button in my Main Activity, and I have a second Activity that makes that button visible. In the second activity I don´t have a problem setting the button visible, but when I return to the Main activity the button is still invisible.
This is my second Activity.
Button button = (Button) inflatedView.findViewById(R.id.showButton);
if (button.getVisibility() == View.INVISIBLE){
button.setVisibility(View.VISIBLE);
}
This is the resume method in the MainActivity
@Override
protected void onResume() {
super.onResume();
}
I already tried making the button visible in the Main Activity, and worked. But I want to make the button visible from the second class. I already tried passing an Intent from the second activity to the Main Activity but I don't know how to process the Intent in the Main Activity. I can not process the Intent in the onResume() or onCreate(), because it will throw a NullPointExeption
.
Thanks for the help.
You should set up a communication between the 2 activities. You can achieve this with
startActivityForResult()
andonActivityResult()
MainActivity:
SecondActivity:
Try this code in
onResume()
of your MainActivity:In second Activity put "your_parameter" parameter as extra to Intent only if you want to make that button visible.
Solve the problem. In the second Activity a have a static boolean variable that begins false. Once the oncreate() in the second Activity is call, the boolean variable is change to true. onresume() in MainActivity i check if the boolean variable is true, and change the visibility of the button.
SecondActivity
MainActivity