67

Using WorkManager on Android 12

 2 years ago
source link: https://medium.com/androiddevelopers/using-workmanager-on-android-12-f7d483ca0ecb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Using WorkManager on Android 12

WorkManager has two new releases for your consideration: 2.6 and 2.7.
Version 2.6 has just reached stable and 2.7 is now considered beta and will be stabilized soon.

WorkManager 2.6 is a fully packed feature release. Instead of WorkManager’s own initialization provider it uses App Startup. This means you’ll have to update the way you removed the default content provider for WorkManager. Here’s the new code:

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities=\"${applicationId}.androidx-startup"
android:exported="false"
tools:node=\"merge">
<!-- If you are using androidx.startup to initialize other components -->
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider><!-- If you want to disable android.startup completely. -->|<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove" />

WorkManager now also provides improved multi-process support using the work-multiprocess artifact.

WorkManager 2.7 & Android 12

However, WorkManager 2.6 is missing one key piece for apps targeting Android 12 (API level 31). Starting in Android 12, foreground service launch restrictions were introduced. These restrictions can leave your app in a state where calling setForeground may cause an exception.

With WorkManager 2.7 expedited jobs were introduced. Expedited jobs allow apps to execute short and high-priority tasks while giving the system better control over access to resources. Expedited jobs are the recommended way to start a task from the background.

We introduced the setExpedited API that is designed to cover most use cases. There are some exceptions for when an app is not subject to foreground service restrictions. The most obvious is, when your app is visible to the user. All other cases are documented here.

To see WorkManager’s setExpedited() API in action, check out our official WorkManager Sample.

You can see a detailed list of changes and improvements made in each WorkManager release in the official release notes, along with specific release notes for Workmanager 2.6 and WorkManager 2.7.

Lastly, if you have any feature requests or issues related to WorkManager, feel free to file an issue in our public tracker.


Recommend

  • 46
    • 掘金 juejin.im 6 years ago
    • Cache

    新架构组件: WorkManager

    5月8号, I/O大会上又推出了两个新的Architeture Component库: Navigation与WorkManager. 这里就先介绍一下WorkManager. 一. WorkManager的一句话介绍 其实就是"管理一些要在后台工作的任务,

  • 67

    Android Jetpack带来WorkManager、Navigation等特性

  • 85

    At Google I/O 2018 , Google announced the WorkManager library as part of the Android Jetpack component set. Moving forward, WorkManager replaces JobScheduler as...

  • 57

    WorkManager is for deferrable background task that needs a guaranteed execution, let’s get started an example to explan how to use it Overview One of the core features in our app are publishin...

  • 43

    Android Jetpack WorkManager Stable Release 2019-03-06ad...

  • 8

    一、WorkManager概述1.1 WorkManager简介在Android应用开发中,或多或少的会有后台任务的需求,根据需求场景的不同,Android为后台任务提供了多种不同的解决方案,如Service、Loader、JobScheduler和AlarmManger等。后台任务通常用在不需要用...

  • 5
    • www.raywenderlich.com 3 years ago
    • Cache

    Scheduling Tasks With Android WorkManager

    Home Android & Kotlin Tutorials Scheduling Tasks With Android Wo...

  • 12

    Using WorkManager in multi-process apps📝 The recent release of WorkManager 2.5.0 enables easier usage in a multi-process environment and provides several stability improvements.So if you have an app...

  • 4

    Experiments with Android WorkmanagerAt Google IO 2018, a new library from the Architecture Components of Android Jetpack, called Android WorkManager was presented. Android WorkManager promises to simplify working with background tasks that ge...

  • 7
    • www.simplifiedcoding.net 3 years ago
    • Cache

    Android WorkManager Tutorial

    Android WorkManager Tutorial – Performing Tasks in BackgroundAnother important thing introduced with Android Jetpack is WorkManager. In this Android WorkManager Tutorial we are going to learn how we can use the WorkM...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK