假设您有一个应用程序 A 打开另一个应用程序 B(例如地图),它不受您控制(即它是一个预先存在的应用程序)。所以现在应用程序 A 在后台。假设发生了一个事件,A 想要在应用 B 的 UI 上显示一个浮动对话框(同时让应用 B 的活动在其后面可见)。这可能吗?
(对此的通常答案是显示通知,但这不是大众市场应用程序,我们正试图非常直接地引起用户的注意。)
目前,我正在尝试做这样的事情:
// This code runs in a class other than app A's main activity,
// and the "activity" variable used here is a reference to that activity.
Intent intent = new Intent(activity, NotificationDialogActivity.class);
// EDIT: I'm not exactly sure whether NEW_TASK helps here or not
// so I removed it, but the REORDER_TO_FRONT would ideally cause
// app A's dialog activity to be moved to the front of the back stack?
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
// The "msg" variable here is just some data being passed to the dialog activity
// I included it here only so it is clear that there is a purpose.
intent.putExtra(NotificationDialogActivity.EXTRA_MSG, msg);
activity.startActivity(intent);
从应用程序 A(在后台的那个)中。
但是,当我这样做时,会在原始应用程序 A 活动和后台堆栈上的应用程序 B 活动之间插入对话框。