Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me with switching between two activities

 
yen hoang
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a google maps application in android. This application has two activities, Activity 1 is used to display map of user's current location, and permits user to input some text to search. Activity 2 is used to display the results on the map.
In activity 1, I have some code to call Activity 2 as following:

public void onClick(View v) {
// get inputed information
requiredValue = textField.getText().toString();
// initiate new Activity
Intent intent = new Intent(Intent.ACTION_VIEW);
// bun is a tool to pass parameters to other Activity
Bundle bun = new Bundle();

double[] coordinate = { latitude, longtitude };
bun.putDoubleArray("coordinate", coordinate);
bun.putString("requiredShopName", requiredValue);

intent.setClass(this, SaleInformation.class);
intent.putExtras(bun);
startActivity(intent);
finish();

}


After clicking Search button, everything works well, the results is displayed on map. That means that Acvitiy 2 has done. But when i search again, after clicking Search button, nothing happens. I guess that both Activity 1 and 2 has died.
Please tell me how to resolve this problem?
Thanks
 
Misha van Tol
Ranch Hand
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After starting Activity 2 you finish() Activity 1, so Activity 1 is gone.
If you can't handle a new search in Activity 2 don't use finish() so you can return to Activity 1 by pressing "back" or execute finish() in Activity 2.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic