views:

761

answers:

3
+2  Q: 

Android new Intent

Hi Im trying to start android market via my app to search similar products. I'm using this code.

    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://market.android.com/search?q=pub:\"some txt\""));
 c.startActivity(intent);

This works fine but when I hit on Home button with in the market and goto home phone home screen. When I open again the app it still shows market results. (i want to goto main menu)

Whats the solution? thanks

A: 

This is not a problem.

When you press home on the Market app it isn't closed, just paused. So when you open it again you resume it. Check Android activity's lifecycle.

Macarse
+3  A: 

If you add the FLAG_ACTIVITY_NO_HISTORY flag to the intent, it won't be kept on the history stack. When the user navigates back to your application, the last activity that was visible before you launched the marketplace will be shown.

Intent intent = new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://market.android.com/search?q=pub:\"some txt\"")); 

c.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
c.startActivity(intent); 

Edit: hackbod is correct: FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET is a better fit for what you need.

Richard Szalay
This worked. Thank you so much
sukitha
+2  A: 

Sorry FLAG_ACTIVITY_NO_HISTORY is probably not the correct solution. Note the semantics of it -- the activity just doesn't appear in the history. Thus if the user taps on one of the things in it to go to the next activity, then pressing back, they will not return to the previous one (but the one before). This is rarely what you want.

Worse, if they go to a second activity from the market activity, press home, and return to your app, the second activity will still be there (it is keeping itself in the history).

The correct flag for this situation is FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET: http://developer.android.com/intl/de/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

hackbod