我正在使用Appcompatv7并在搜索视图获得焦点时获得以下异常:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(Native Method)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.InputChannel$1.createFromParcel(InputChannel.java:39)
at android.view.InputChannel$1.createFromParcel(InputChannel.java:36)
at com.android.internal.view.InputBindResult.<init>(InputBindResult.java:62)
at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:102)
at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:99)
at com.android.internal.view.IInputMethodManager$Stub$Proxy.startInput(IInputMethodManager.java:664)
at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1286)
at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1408)
at android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow(InputMethodManager.java:1062)
at android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow(InputMethodManager.java:1041)
at android.support.v7.widget.SearchView.setImeVisibility(SearchView.java:870)
at android.support.v7.widget.SearchView.access$2100(SearchView.java:103)
at android.support.v7.widget.SearchView$SearchAutoComplete.onKeyPreIme(SearchView.java:1697)
at android.view.View.dispatchKeyEventPreIme(View.java:7973)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewGroup.dispatchKeyEventPreIme(ViewGroup.java:1458)
at android.view.ViewRootImpl$ViewPreImeInputStage.processKeyEvent(ViewRootImpl.java:4497)
at android.view.ViewRootImpl$ViewPreImeInputStage.onProcess(ViewRootImpl.java:4490)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4214)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4268)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4237)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4348)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4245)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4405)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4214)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6594)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6508)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6479)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6444)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6674)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5692)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
我该如何预防?
这是appcompat v7库的常见问题。我错过了实施的内容
提前致谢
这是Java实现:
public boolean onCreateOptionsMenu(Menu menu) {
// getSupportMenuInflater().inflate(R.menu.activity_main, menu);
this.menu = menu;
searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint("Search");
searchView.setFocusable(true);
searchView.setOnQueryTextListener(this);
searchMenuItem = menu.add("Search");
searchMenuItem.setIcon(R.drawable.ic_action_search);
MenuItemCompat.setActionView(searchMenuItem, searchView);
MenuItemCompat.setShowAsAction(searchMenuItem,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS
| MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
MenuItemCompat.setOnActionExpandListener(searchMenuItem,
new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
setSliderSelectionAsPerFocusedScreen();
listview.setVisibility(View.GONE);
listvisible = false;
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
return true; // Return true to expand action view
}
});
return true;
}
注意:我在kitkat上遇到这个例外,在一些设备上也是如此