@@ -91,8 +91,10 @@ public TaskStackBuilder addNextIntent(Intent nextIntent) {
9191
9292 /**
9393 * Add the activity parent chain as specified by the
94- * {@link android.R.attr#parentActivityName parentActivityName} attribute of the activity
95- * (or activity-alias) element in the application's manifest to the task stack builder.
94+ * {@link Activity#getParentActivityIntent() getParentActivityIntent()} method of the activity
95+ * specified and the {@link android.R.attr#parentActivityName parentActivityName} attributes
96+ * of each successive activity (or activity-alias) element in the application's manifest
97+ * to the task stack builder.
9698 *
9799 * @param sourceActivity All parents of this activity will be added
98100 * @return This TaskStackBuilder for method chaining
@@ -155,6 +157,41 @@ public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) {
155157 return this ;
156158 }
157159
160+ /**
161+ * Add the activity parent chain as specified by the
162+ * {@link android.R.attr#parentActivityName parentActivityName} attribute of the activity
163+ * (or activity-alias) element in the application's manifest to the task stack builder.
164+ *
165+ * @param sourceActivityName Must specify an Activity component. All parents of
166+ * this activity will be added
167+ * @return This TaskStackBuilder for method chaining
168+ */
169+ public TaskStackBuilder addParentStack (ComponentName sourceActivityName ) {
170+ final int insertAt = mIntents .size ();
171+ PackageManager pm = mSourceContext .getPackageManager ();
172+ try {
173+ ActivityInfo info = pm .getActivityInfo (sourceActivityName , 0 );
174+ String parentActivity = info .parentActivityName ;
175+ Intent parent = new Intent ().setComponent (
176+ new ComponentName (info .packageName , parentActivity ));
177+ while (parent != null ) {
178+ mIntents .add (insertAt , parent );
179+ info = pm .getActivityInfo (parent .getComponent (), 0 );
180+ parentActivity = info .parentActivityName ;
181+ if (parentActivity != null ) {
182+ parent = new Intent ().setComponent (
183+ new ComponentName (info .packageName , parentActivity ));
184+ } else {
185+ parent = null ;
186+ }
187+ }
188+ } catch (NameNotFoundException e ) {
189+ Log .e (TAG , "Bad ComponentName while traversing activity parent metadata" );
190+ throw new IllegalArgumentException (e );
191+ }
192+ return this ;
193+ }
194+
158195 /**
159196 * @return the number of intents added so far.
160197 */
0 commit comments