@@ -47,6 +47,7 @@ public AppSettingsDialog[] newArray(int size) {
4747 private final String mPositiveButtonText ;
4848 private final String mNegativeButtonText ;
4949 private final int mRequestCode ;
50+ private final int mIntentFlags ;
5051
5152 private Object mActivityOrFragment ;
5253 private Context mContext ;
@@ -58,6 +59,7 @@ private AppSettingsDialog(Parcel in) {
5859 mPositiveButtonText = in .readString ();
5960 mNegativeButtonText = in .readString ();
6061 mRequestCode = in .readInt ();
62+ mIntentFlags = in .readInt ();
6163 }
6264
6365 private AppSettingsDialog (@ NonNull final Object activityOrFragment ,
@@ -66,14 +68,16 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,
6668 @ Nullable String title ,
6769 @ Nullable String positiveButtonText ,
6870 @ Nullable String negativeButtonText ,
69- int requestCode ) {
71+ int requestCode ,
72+ int intentFlags ) {
7073 setActivityOrFragment (activityOrFragment );
7174 mThemeResId = themeResId ;
7275 mRationale = rationale ;
7376 mTitle = title ;
7477 mPositiveButtonText = positiveButtonText ;
7578 mNegativeButtonText = negativeButtonText ;
7679 mRequestCode = requestCode ;
80+ mIntentFlags = intentFlags ;
7781 }
7882
7983 static AppSettingsDialog fromIntent (Intent intent , Activity activity ) {
@@ -147,6 +151,11 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
147151 dest .writeString (mPositiveButtonText );
148152 dest .writeString (mNegativeButtonText );
149153 dest .writeInt (mRequestCode );
154+ dest .writeInt (mIntentFlags );
155+ }
156+
157+ int getIntentFlags () {
158+ return mIntentFlags ;
150159 }
151160
152161 /**
@@ -163,6 +172,7 @@ public static class Builder {
163172 private String mPositiveButtonText ;
164173 private String mNegativeButtonText ;
165174 private int mRequestCode = -1 ;
175+ private boolean mOpenInNewTask = false ;
166176
167177 /**
168178 * Create a new Builder for an {@link AppSettingsDialog}.
@@ -295,6 +305,17 @@ public Builder setRequestCode(int requestCode) {
295305 return this ;
296306 }
297307
308+ /**
309+ * Set whether the settings screen should be opened in a separate task. This is achieved by
310+ * setting {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK#FLAG_ACTIVITY_NEW_TASK} on
311+ * the Intent used to open the settings screen.
312+ */
313+ @ NonNull
314+ public Builder setOpenInNewTask (boolean openInNewTask ) {
315+ mOpenInNewTask = openInNewTask ;
316+ return this ;
317+ }
318+
298319 /**
299320 * Build the {@link AppSettingsDialog} from the specified options. Generally followed by a
300321 * call to {@link AppSettingsDialog#show()}.
@@ -311,14 +332,20 @@ public AppSettingsDialog build() {
311332 mContext .getString (android .R .string .cancel ) : mNegativeButtonText ;
312333 mRequestCode = mRequestCode > 0 ? mRequestCode : DEFAULT_SETTINGS_REQ_CODE ;
313334
335+ int intentFlags = 0 ;
336+ if (mOpenInNewTask ) {
337+ intentFlags |= Intent .FLAG_ACTIVITY_NEW_TASK ;
338+ }
339+
314340 return new AppSettingsDialog (
315341 mActivityOrFragment ,
316342 mThemeResId ,
317343 mRationale ,
318344 mTitle ,
319345 mPositiveButtonText ,
320346 mNegativeButtonText ,
321- mRequestCode );
347+ mRequestCode ,
348+ intentFlags );
322349 }
323350
324351 }
0 commit comments