|
24 | 24 | import android.content.ContentUris; |
25 | 25 | import android.content.ContentValues; |
26 | 26 | import android.content.Context; |
| 27 | +import android.content.ContextWrapper; |
27 | 28 | import android.content.CursorEntityIterator; |
28 | 29 | import android.content.Entity; |
29 | 30 | import android.content.EntityIterator; |
@@ -7711,9 +7712,19 @@ public static void showQuickContact(Context context, View target, Uri lookupUri, |
7711 | 7712 | */ |
7712 | 7713 | public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode, |
7713 | 7714 | 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 | + |
7714 | 7726 | // 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); |
7717 | 7728 |
|
7718 | 7729 | intent.setData(lookupUri); |
7719 | 7730 | intent.setSourceBounds(target); |
|
0 commit comments