例外是:
FATAL EXCEPTION: main java.lang.NullPointerException at android.view.WindowManagerImpl.reportNewConfiguration(WindowManagerImpl.java:427) at android.app.ActivityThread.handleUpdatePackageCompatibilityInfo(ActivityThread.java:2801) at android.app.ActivityThread.access$2700(ActivityThread.java:122) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:132) at android.app.ActivityThread.main(ActivityThread.java:4123) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:491) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) at dalvik.system.NativeStart.main(Native Method)
我的测试代码:
TestActivity.java(由Wizerd生成)
package com.test; import android.app.Activity; public class TestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent(this,TestService.class); startService(intent); } }
TestService.java(大多数函数都是空的)
Package com.test; import android.content.ComponentName; public class TestService extends Service { private boolean m_connected = false; private ServiceConnection m_connInitService = new ServiceConnection() { public void onServiceConnection(ComponentName className,IBinder service) { m_connected = true; } public void onServicedisconnected(ComponentName className) { } }; public static class TestServiceBinder extends Binder { } public IBinder onBind(Intent intent) { return new TestServiceBinder(); } public void onDestroy() { super.onDestroy(); } public int onStartCommand(Intent intent,int flags,int startId) { return 1; } }
如果我在同一过程中没有服务或服务运行测试应用程序,屏幕兼容性开关将不会导致任何问题.但是,我不明白为什么服务会在屏幕兼容性切换期间导致系统异常.这是因为服务流程是非UI流程吗?哪个可能会触发Android核心代码中的错误?
解决方法
android:process
If the name assigned to this attribute begins with a colon (‘:’),a
new process,private to the application,is created when it’s needed
and the service runs in that process. If the process name begins with
a lowercase character,the service will run in a global process of
that name,provided that it has permission to do so. This allows
components in different applications to share a process,reducing
resource usage.
因此,如果您指定以小写字母开头的进程名称,则应具有执行此操作的权限.但我不知道检查这些权限的位置.也许它们在WindowManagerImpl中被检查,它找不到这个全局进程,因此返回null.这只是一个假设.
原文地址:https://www.jb51.cc/android/314830.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。