Toofan
Toofan

Reputation: 150

ACTION_WEB_SEARCH opens the right search query for the first time only

I have an app which opens the ACTION_WEB_SEARCH intent to open the search app. It works fine the first time, but if the activity is started again, the search parameters don't change.

public static void launchWebSearch(Context context, String query) {
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, query);
    context.startActivity(intent);
}

The above code will open the google search app with the query in it for the first time. Next time its invoked, it will still open the google search app but the query won't change and will still have the old search results.

Upvotes: 3

Views: 1105

Answers (3)

Neamar
Neamar

Reputation: 391

Faced the same problem,

After some digging, i discovered that uninstalling the update from "Google Search" fixed the problem, so this is indeed related to Google Now (Google Quicksearch, the stock version, works perfectly).

I fixed it by adding the following flags to my search intent:

    Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
    search.putExtra(SearchManager.QUERY, query);
    // In the latest Google Now version, ACTION_WEB_SEARCH is broken when used with FLAG_ACTIVITY_NEW_TASK.
    // Adding FLAG_ACTIVITY_CLEAR_TASK seems to fix the problem.
    search.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    search.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Upvotes: 1

matiash
matiash

Reputation: 55380

The only thing I believe could cause this is an incorrect implementation of the activity that handles the ACTION_WEB_SEARCH intent (such as being declared as singleInstance or singleTop and not implementing onNewIntent()). Possibly Samsung devices ship with a customized version of the search app?

I would suggest using PackageManager.queryIntentActivities() to see if there are any other possible matches for ACTION_WEB_SEARCH.

Upvotes: 1

todd
todd

Reputation: 1286

I couldn't reproduce your error either; I suspect the problem may be somewhere else in your code.

Just a shot in the dark but you may want to try adding the following flag to your intent:

intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

Upvotes: 1

Related Questions