如何在模拟器上模拟IllegalStateException以获取新的Background限制

时间:2018-06-21 08:23:15

标签: android debugging service android-emulator background-process

在我将应用程序更新到targetSdkVersion 27后,我发现我的应用程序在Google Play中崩溃了。

崩溃的原因是由于在Oreo中引入了新的后台执行限制,我呼吁在Application对象onCreate上启动一些TTS服务。 调用startService(intent)时,将引发IllegalStateException。

我正在尝试在使用Android 8.1(API 27)的模拟器上重现此错误。但是,它没有问题。

我尝试在开发人员设置\背景进程限制中设置“无后台进程”。但是我的应用程序在模拟器上仍然可以正常工作。

我的服务正在另一个进程中运行:

<service
    android:name=".services.Text2SpeechService"
    android:enabled="true"
    android:exported="false"
    android:process="my.app.services.Text2SpeechService" />

问题:如何使仿真器模拟此错误?

0 个答案:

没有答案