@@ -47,6 +47,7 @@ public AppSettingsDialog[] newArray(int size) {
47
47
private final String mPositiveButtonText ;
48
48
private final String mNegativeButtonText ;
49
49
private final int mRequestCode ;
50
+ private final int mIntentFlags ;
50
51
51
52
private Object mActivityOrFragment ;
52
53
private Context mContext ;
@@ -58,6 +59,7 @@ private AppSettingsDialog(Parcel in) {
58
59
mPositiveButtonText = in .readString ();
59
60
mNegativeButtonText = in .readString ();
60
61
mRequestCode = in .readInt ();
62
+ mIntentFlags = in .readInt ();
61
63
}
62
64
63
65
private AppSettingsDialog (@ NonNull final Object activityOrFragment ,
@@ -66,14 +68,16 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,
66
68
@ Nullable String title ,
67
69
@ Nullable String positiveButtonText ,
68
70
@ Nullable String negativeButtonText ,
69
- int requestCode ) {
71
+ int requestCode ,
72
+ int intentFlags ) {
70
73
setActivityOrFragment (activityOrFragment );
71
74
mThemeResId = themeResId ;
72
75
mRationale = rationale ;
73
76
mTitle = title ;
74
77
mPositiveButtonText = positiveButtonText ;
75
78
mNegativeButtonText = negativeButtonText ;
76
79
mRequestCode = requestCode ;
80
+ mIntentFlags = intentFlags ;
77
81
}
78
82
79
83
static AppSettingsDialog fromIntent (Intent intent , Activity activity ) {
@@ -147,6 +151,11 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
147
151
dest .writeString (mPositiveButtonText );
148
152
dest .writeString (mNegativeButtonText );
149
153
dest .writeInt (mRequestCode );
154
+ dest .writeInt (mIntentFlags );
155
+ }
156
+
157
+ int getIntentFlags () {
158
+ return mIntentFlags ;
150
159
}
151
160
152
161
/**
@@ -163,6 +172,7 @@ public static class Builder {
163
172
private String mPositiveButtonText ;
164
173
private String mNegativeButtonText ;
165
174
private int mRequestCode = -1 ;
175
+ private boolean mOpenInNewTask = false ;
166
176
167
177
/**
168
178
* Create a new Builder for an {@link AppSettingsDialog}.
@@ -295,6 +305,17 @@ public Builder setRequestCode(int requestCode) {
295
305
return this ;
296
306
}
297
307
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
+
298
319
/**
299
320
* Build the {@link AppSettingsDialog} from the specified options. Generally followed by a
300
321
* call to {@link AppSettingsDialog#show()}.
@@ -311,14 +332,20 @@ public AppSettingsDialog build() {
311
332
mContext .getString (android .R .string .cancel ) : mNegativeButtonText ;
312
333
mRequestCode = mRequestCode > 0 ? mRequestCode : DEFAULT_SETTINGS_REQ_CODE ;
313
334
335
+ int intentFlags = 0 ;
336
+ if (mOpenInNewTask ) {
337
+ intentFlags |= Intent .FLAG_ACTIVITY_NEW_TASK ;
338
+ }
339
+
314
340
return new AppSettingsDialog (
315
341
mActivityOrFragment ,
316
342
mThemeResId ,
317
343
mRationale ,
318
344
mTitle ,
319
345
mPositiveButtonText ,
320
346
mNegativeButtonText ,
321
- mRequestCode );
347
+ mRequestCode ,
348
+ intentFlags );
322
349
}
323
350
324
351
}
0 commit comments