Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search widget call OnNewIntent twice

I have an activity in which I want to search. When I click to search, event OnNewIntent it is called twice... What I'm doing wrong?

I'm creating Searchview like this

public override bool OnCreateOptionsMenu(IMenu menu) 
{

    searchView = new SearchView(this);
    var searchManager = (SearchManager)GetSystemService(Context.SearchService);
    var searchableInfo = searchManager.GetSearchableInfo(ComponentName);

    searchView.SetSearchableInfo(searchableInfo);
    var search_item = menu.Add(new Java.Lang.String("Search"));
    search_item.SetActionView(searchView);
    search_item.SetShowAsAction(ShowAsAction.IfRoom);        

    var edit = menu.Add(0, insertItemID, 0, "Insert");
    edit.SetShowAsAction(ShowAsAction.IfRoom);
    edit.SetIcon(Android.Resource.Drawable.IcMenuAdd);

    return base.OnCreateOptionsMenu(menu); 
}

Log:

10-17 07:45:45.491 I/ActivityManager(  900): START {act=android.intent.action.SEARCH flg=0x10000000 cmp=Intranet.Intranet/intranet.screens.ContactListActivity (has extras)} from pid 2971
10-17 07:45:47.562 W/EGL_emulation( 2971): eglSurfaceAttrib not implemented
10-17 07:45:47.562 I/ActivityManager(  900): START {act=android.intent.action.SEARCH flg=0x10000000 cmp=Intranet.Intranet/intranet.screens.ContactListActivity (has extras)} from pid 2971
10-17 07:45:48.472 D/OpenGLRenderer( 2971): Flushing caches (mode 0)
10-17 07:45:48.481 D/dalvikvm(  900): GC_CONCURRENT freed 559K, 13% free 7991K/9159K, paused 1ms+1ms
10-17 07:45:48.500 W/InputManagerService(  900): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b48b3470
10-17 07:45:48.561 D/dalvikvm(  963): GC_CONCURRENT freed 389K, 41% free 6027K/10183K, paused 0ms+0ms
like image 865
c1rus Avatar asked Oct 17 '12 07:10

c1rus


2 Answers

I assume you have made your search activity single top and overidden onNewIntent to call setIntent prior to processing the search intent. If so, it's a bug in SearchView when using the emulator hardware keyboard.

http://books.google.com/books?id=OFXJXbCXjTgC&pg=PT771&lpg=PT771&dq=android+search+intent+sent+twice+bug&source=bl&ots=Ora1AJjh4A&sig=9yFBjCwJ1ARbXePHzcPYpG_QdFQ&hl=en&sa=X&ei=bbddUpbZCcLi4AOiioCIAw&ved=0CD8Q6AEwAw#v=onepage&q=android%20search%20intent%20sent%20twice%20bug&f=false

You can disable the hardware keyboard in your emulator by going to Settings -> Launguage & input and click on Default.

If you use the soft keyboard you should only see it once.

like image 136
museofwater Avatar answered Oct 19 '22 09:10

museofwater


I had a similar problem with DatePickerDialog...it seems to be an api bug. It works on android 2.2, but not on android 4.0+. My solution was:

int timesCalled = 0;
public void yourMethod(){
    timesCalled += 1;
    if ((timesCalled % 2) == 0) {
       //do your stuff here
    }
}

Its not the clearest solution, but it works for me. Hope this can help.

like image 32
Dima Avatar answered Oct 19 '22 08:10

Dima