0

I'm trying to develop an app which has two editText fields for entering location. So I made two java files

1.MapsActivity.java(with activity_maps.xml)
2.AutoComplete.java(with autocomplete.xml)

In MapsActivity while clicking the 'from' text field, it will open the AutoComplete activity and after clicking any of the suggestions in it will open a fresh MapsActivity and places the clicked item . Likewise for 'to' text field also.

I am using Intents to pass the clicked values. So at last, five activities are opened when the two text boxes are filled. When I click back button ,it is showing the auto complete activity used the previous time.

Question:

  1. Is any other way to close a particular activity with same name running behind?

  2. Is there any other way to pass values by super.backpressed(); ?

enter image description here

Michiyo
  • 1,161
  • 1
  • 14
  • 33
Surya
  • 47
  • 8
  • Why are you starting new activity when EditText is clicked? – Jas Feb 29 '16 at 05:25
  • @Jas actually I want to show the user ,a set of suggestions about the places they are searching for..! From the same activity, it will be difficult I think.. – Surya Feb 29 '16 at 05:28
  • You can easily do this using a custom alert dialog with your suggestions shown as list – Jas Feb 29 '16 at 05:38
  • Thank you Jas.. But whether it will update the suggestions for every letter being changed? – Surya Feb 29 '16 at 05:43

2 Answers2

2

You can try using startActivityForResult() method. That way you can use the result from the second activity in the first and also you wouldn't need to start a new activity. You can read up on it here startActivityForResult

TechnoBlahble
  • 633
  • 5
  • 14
0

try to clear backstack/clear_top/single_top using the intent. Just add/set flags in intent. or finish activity after startActivity. or you can override the onBackPressed method to call the specific activity.

Ankush Bist
  • 1,862
  • 1
  • 15
  • 32