permaculture playing cards
The moose likes Android and the fly likes Help me with switching between two activities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Help me with switching between two activities" Watch "Help me with switching between two activities" New topic

Help me with switching between two activities

yen hoang
Ranch Hand

Joined: Apr 05, 2009
Posts: 58
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?

I love Mozart (^o^)
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

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.
I agree. Here's the link:
subject: Help me with switching between two activities
It's not a secret anymore!