別のアプリ B (地図など) を開くアプリ A があるとします。このアプリはあなたによって制御されていません(つまり、既存のアプリです)。したがって、アプリ 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 アクティビティの間にダイアログが挿入されます。