Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use an Android SearchView without singleTop?
    primarykey
    data
    text
    <p>I have an activity that I normally want to exist in multiple tasks, so that the [Back] button restores a previous state; however, I also want to use a <a href="http://developer.android.com/reference/android/widget/SearchView.html" rel="noreferrer">SearchView</a> with an existing activity, without pushing a new one onto the task stack (since I want to search what's currently displayed). Here's my problem:</p> <ul> <li>If I set the activity's launch mode to "singleTop", the SearchView works with the current activity, but <a href="http://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)" rel="noreferrer">Context.startActivity</a> does not add new activities to the stack.</li> <li>If I set the activity's launch mode to "standard", <em>startActivity</em> adds new activities to the stack, but SearchView also creates a new (empty) activity, instead of searching the existing one.</li> </ul> <p>I can't find any way make SearchView use intent flags (e.g. <a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_SINGLE_TOP" rel="noreferrer">FLAG_ACTIVITY_SINGLE_TOP</a>. I tried going the other way around, setting launch mode to "singleTop" then adding <a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK" rel="noreferrer">FLAG_ACTIVITY_NEW_TASK</a> to every intent, but that worked only when launching from a different activity class; when I try to launch a new instance of an activity from its own class, Android didn't respect FLAG_ACTIVITY_NEW_TASK and didn't push a new task onto the stack.</p> <p>Perhaps there's something I can do in <a href="http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)" rel="noreferrer">Activity.onNewIntent</a> to force the activity to clone itself then.</p> <p>I'm on the verge of giving up on SearchView and just writing my own custom widget, despite that fact that <em>"Beginning in Android 3.0, using the SearchView widget as an item in the action bar is the preferred way to provide search in your app"</em> (<a href="http://developer.android.com/training/search/setup.html" rel="noreferrer">Source</a>) — so far, it seems just too inflexible and non-configurable to be useful in non-trivial cases.</p> <p>Has anyone found a solution to this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload