Reputation: 37
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,
Upvotes: 1
Views: 81
Reputation: 438
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();
}
Upvotes: 0
Reputation: 2712
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.
Upvotes: 2
Reputation: 510
just clear the EditText field before you start a new activity
editTextTitle.setText("");
editTextDescription.setText("");
intent.startActivity();
Upvotes: 0