谷歌最近弃用了 IntentService:https ://android.googlesource.com/platform/frameworks/base.git/+/6f8b09029932dfd24945202017639754b00acc2e
IntentService 的文档现在说:
* @deprecated IntentService is subject to all the
* <a href="/preview/features/background.html">background execution limits</a>
* imposed with Android 8.0 (API level 26). Consider using {@link androidx.work.WorkManager}
* or {@link androidx.core.app.JobIntentService}, which uses jobs
* instead of services when running on Android 8.0 or higher.
Run Code Online (Sandbox Code Playgroud)
那么JobIntentService和WorkManager有什么区别,在什么情况下推荐使用哪一个呢?
谷歌在这个页面上甚至没有提到 JobIntentService,他们只提到了 WorkManager:https : //developer.android.com/guide/background
我正在尝试测试应用程序工作流程。导航组件已用于定义应用程序工作流。基于此参考(https://developer.android.com/guide/navigation/navigation-testing),使用 FragmentScenario 测试从一个片段到另一个片段的导航。
在 build.gradle 中添加了以下依赖项
debugImplementation("androidx.fragment:fragment-testing:1.1.0-beta01") {
exclude group: 'androidx.test', module: 'core'
}
用于访问api launchFragmentInContainer
已经使用 MockK 来模拟 navController
下面是示例片段
@RelaxedMockK
private lateinit var navController: NavController
@Before
fun setup() {
MockKAnnotations.init(this)
}
@Test
fun navigationToSecondFragmentTest() {
val secondFragmentScenario = launchFragmentInContainer<SecondFragment>()
secondFragmentScenario.onFragment {
Navigation.setViewNavController(it.requireView(), navController)
}
onView(ViewMatchers.withId(R.id.btn)).perform(ViewActions.click())
verify{
navController.navigate(R.id.secondFragment)
}
}
Run Code Online (Sandbox Code Playgroud)
我的期望是通过测试用例,但我收到以下运行时错误
`java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState`
Run Code Online (Sandbox Code Playgroud) android-fragments android-testing android-architecture-components android-architecture-navigation