1

I'm a new android programming beginner :) .

I have made a simple app which adding places .

1- Main activity include buttons{Places , Add place , Favorites Places }

so let's assume we are in the "Add place" activity , we type tite and description and add the place to arrayList, and move on to Places which has this list ..

The problem is when I type back, I get back the details I wrote about the place, but I'm trying to clear it when I press back in the phone ...

how can I do this to avoid crashes ?

Thanks all

-- Update : Thanks to all people who reply trying to help me, that's awesome :) I just added :

@Override
    public void onBackPressed(){
        Intent intent = new Intent(PlacesActivity.this,MainActivity.class);
        startActivity(intent);

    }

This solution was suggested by : Arsen Sench :)

in the activity that I don't want to press back,

Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42

3 Answers3

2

You can do one thing here. Before jumping to another activity View Places , just clear all the edittext there.

edittext.setText("");

Try this. Will help you.

Jay Vyas
  • 2,674
  • 5
  • 27
  • 58
0

just clear the EditText field before you start a new activity

editTextTitle.setText("");
editTextDescription.setText("");

intent.startActivity();
  • I tried this, but Unfortunately it doesn't work, Cause i also take a photo from the gallery so when I took it and back to the Add place to load the image with details will be the onresume clean .. instead I'm trying to make onResume in PlacesActivity, to get back to the main or something – Haytham Egbariah Dec 13 '16 at 06:46
  • you should store the image path/data string into SharePref / just make a public static String in your activity to access back when you back to the activity, and load the image if needed – Aldi Renaldi Gunawan Dec 13 '16 at 07:03
0

You can use startActivity() from both classes. Or you can use startActivityForResult(). Here is example of using startActivity() from both activites.

From first Activity

Intent i = new Intent(YOURFIRSTACTIVITY.this,YOURSECONDACTIVITY.class);
startactivity(i);
finish();

From Second Activity

@Override
public void onBackPressed()
{
    Intent i = new Intent(YOURSECONDACTIVITY.this,YOURFIRSTACTIVITY.class);
    startactivity(i);
    finish();
}
Arsen Sench
  • 438
  • 4
  • 18