Language

JobInfo.Builder.SetImportantWhileForeground(Boolean) Method

Definition

Requests that the job be treated as important while the scheduling app is in the foreground or on the temporary allowlist for background restrictions. This flag is ignored on Android 16 and later.

[Android.Runtime.Register("setImportantWhileForeground", "(Z)Landroid/app/job/JobInfo$Builder;", "", ApiSince=28)]
public Android.App.Job.JobInfo.Builder? SetImportantWhileForeground(bool importantWhileForeground);
[<Android.Runtime.Register("setImportantWhileForeground", "(Z)Landroid/app/job/JobInfo$Builder;", "", ApiSince=28)>]
member this.SetImportantWhileForeground : bool -> Android.App.Job.JobInfo.Builder

Parameters

importantWhileForeground
Boolean

Whether to request relaxed doze restrictions for this job when the app is in the foreground. The default is false. This flag is ignored on Android 16 and later.

Returns

This builder instance, including on Android 16 and later where the flag has no effect.

Attributes

Remarks

This method was deprecated in API level 31. Use SetExpedited(Boolean) instead.

On Android 9 through Android 15, setting this to true indicates that this job is important while the scheduling app is in the foreground or on the temporary allowlist for background restrictions. This means that the system will relax doze restrictions on this job during this time. Apps should use this flag only for short jobs that are essential for the app to function properly in the foreground. Note that once the scheduling app is no longer allowlisted from background restrictions and in the background, or the job failed due to unsatisfied constraints, this job should be expected to behave like other jobs without this flag.

On Android 13 through Android 15, jobs marked as important-while-foreground are given High priority by default.

Beginning with Android 16, this flag is ignored regardless of the calling app's target SDK version. IsImportantWhileForeground always returns false. Apps should use SetExpedited(Boolean) with true to indicate that this job is important and needs to run as soon as possible.

Android reference for android.app.job.JobInfo.Builder.setImportantWhileForeground.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to