Repository files navigation
Add saved instance state code from slides (line 38)
add private static final String BUTTON_STATE = "BUTTON_STATE_KEY"; on line 21 (replace the TODO)
override (ctrl+o) onSaveInstanceState on line 84
protected void onSaveInstanceState(@NonNull Bundle outState) {...};
create getMessage() on line 64
move the code from the onClick to the method.
Run it.
why is it still broken?
fix the todo on line 43
add a long click listener on line 53
button.SetOnL AND PRESS TAB
new View.O and press tab.
Intent intent = ChildActivity.intentFactory(getApplicationContext(),messageOne);
Create a child activity
add a textView
add a button
MAKE NOTE OF THE ID
remove the EdgeToEdge code
remove the ViewCompat code
create an ActivityChildBinding object
binding = ActivityChildBinding.inflate(getLayoutInflator);
setContentView(binding.)
declare a boolean showMessage1Child somewhere near the top of the class (similar to messageOne in MainActivity)
Declare a SHOW_MESSAGE_ONE constant in ChildActivity, similar to the BUTTON_STATE variable in MainActivity
Use SHOW_MESSAGE_ONE in the intentFactory method in the ChildActivity when adding a boolean extra
Use SHOW_MESSAGE_ONE to RETRIEVE the boolean extra and store the returned value in showMessage1Child
getIntent().getBooleanExtra(...)
Use the value stored in showMessage1Child to set the text that is displayed on the button
binding.childActivityButton.setText(showMessage1Child ? "TRUE!" : "FALSE!");
create an intent factory in ChildActivity
TEST IT
add an onLongClickListener to the button on the child activity
Use the intent factory from MainActivty to switch from child activity to MainActivity
update MainActivity to use the extra.
About
Inital code for the lifecycle activity
Resources
Stars
Watchers
Forks
You can’t perform that action at this time.