This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me with switching between two activities  RSS feed

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);


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?
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!