0

I am nearly finished with my first Android App, but there is one thing that still bothers me: I have an activity with EditText fields and a "Start"-button that leads to a new Activity. When the user presses the back-button (the one thats on the phone), I get back to my first Activity. Can I change this and define a whole new Activity? A modified version of my first Activity?

Here is what I want to achieve:

First Activity - - > (start-button clicked) - - > Second Activity - - > (back-button clicked) - - > First Activity, modified.

Thanks for any help!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    What do you mean by "modified"? – Tom Alabaster Feb 14 '18 at 13:24
  • I have a belonging xml-layout and I want this to appear at the start and when the back button is clicked. But I modify this layout programmatically in the beginning.. and when the back-button is clicked I want to modify the layout in a different way! –  Feb 14 '18 at 13:27

2 Answers2

0

Use startActivityForResult and onActivityResult.

An example of this is here.

You will put your layout manipulation code as it were in the onActivityResult method in your first activity, and start the second activity using startActivityForResult.

Tom Alabaster
  • 965
  • 6
  • 12
0

override onBackPressed() in your second activity and start your modified activity from there. Something like:

@Override
public void onBackPressed()
{
     //start your activity here
    //make sure you remove the super call
}
Clapa Lucian
  • 590
  • 2
  • 7
  • 14