Skip to content

Commit bba33cd

Browse files
author
Makoto Onuki
committed
Fix bug 6563184: API compatibility issue with quick contact
Add FLAG_ACTIVITY_NEW_TASK if the starting contentext is not an activity. Change-Id: I3c03a1acc12798d846c6f321cf46f77a2833172b
1 parent 58296ba commit bba33cd

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

core/java/android/provider/ContactsContract.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.content.ContentUris;
2525
import android.content.ContentValues;
2626
import android.content.Context;
27+
import android.content.ContextWrapper;
2728
import android.content.CursorEntityIterator;
2829
import android.content.Entity;
2930
import android.content.EntityIterator;
@@ -7711,9 +7712,19 @@ public static void showQuickContact(Context context, View target, Uri lookupUri,
77117712
*/
77127713
public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
77137714
String[] excludeMimes) {
7715+
// When launching from an Activiy, we don't want to start a new task, but otherwise
7716+
// we *must* start a new task. (Otherwise startActivity() would crash.)
7717+
Context actualContext = context;
7718+
while ((actualContext instanceof ContextWrapper)
7719+
&& !(actualContext instanceof Activity)) {
7720+
actualContext = ((ContextWrapper) actualContext).getBaseContext();
7721+
}
7722+
final int intentFlags = (actualContext instanceof Activity)
7723+
? Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
7724+
: Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK;
7725+
77147726
// Launch pivot dialog through intent for now
7715-
final Intent intent = new Intent(ACTION_QUICK_CONTACT)
7716-
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
7727+
final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags);
77177728

77187729
intent.setData(lookupUri);
77197730
intent.setSourceBounds(target);

0 commit comments

Comments
 (0)