三星:关闭电源时 InputMethodService 崩溃(NullPointerException)

Samsung: On power off InputMethodService is crashed (NullPointerException)

无法检测 issue.This 三星设备特有的问题。

我在日志中得到的另一件事:

"Unexpected null in startExtractingText : mExtractedText = null, input connection = com.android.internal.view.InputConnectionWrapper"


11-23 15:44:06.463 21778-21778/? W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.inputmethodservice.InputMethodService.forceExtractEditTextClose()' on a null object reference
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.inputmethodservice.ExtractEditText.onScreenStateChanged(ExtractEditText.java:246)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.View.dispatchScreenStateChanged(View.java:15375)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewGroup.dispatchScreenStateChanged(ViewGroup.java:3164)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.view.ViewRootImpl.onDisplayChanged(ViewRootImpl.java:1171)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.hardware.display.DisplayManagerGlobal$DisplayListenerDelegate.handleMessage(DisplayManagerGlobal.java:724)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.os.Looper.loop(Looper.java:158)
11-23 15:44:06.463 21778-21778/? W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7225)
11-23 15:44:06.463 21778-21778/? W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
11-23 15:44:06.463 21778-21778/? W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
11-23 15:44:06.463 21778-21778/? W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我已经自己解决了这个问题。在我的例子中,我在重写的方法 setExtractView(View view) 上添加了我的自定义视图。但我并没有先删除视图。

让我解释一下:

@Override
public void setExtractView(View view) {
  // You have to do this if you are not doing so
  view.removeAllViews() ; // This is the line 
  view.addView(yourView) ; // Here you can put your own  Custom view 
  super.setExtractView(view);
} 

这对我有用。我希望当您遇到

这样的问题时,这会对您有所帮助
"Unexpected null in startExtractingText : mExtractedText = null, input connection = com.android.internal.view.InputConnectionWrapper"