How to keep a dialog/activity on the top of other activities, no matter if user switch between activities,it should be alive all the time.
-
display a dialog in onResume() of every activity dismiss it in onPause() – Raghunandan Apr 04 '13 at 13:33
-
@Raghunandan well, i think this isn't a good approach – nsinvocation Apr 04 '13 at 13:39
-
how do you think this not a good approach? – Raghunandan Apr 04 '13 at 13:40
-
@Raghunandan That would result in the dialog being recreated every time the user switches activities, it wouldn't keep it always on top. – Jan 21 '14 at 15:40
2 Answers
You can use Relative layout as a parent, by using Relative Layout, you can overlap the other layout. So, you have to use to two child layout of relative layout. In the one child you will have popup, and in another layout you have to keep changing your layout..
If you want this across multiple activities. You must create a separate layout and include that in all activities, and create an interface to handle the button events in the popup.
or
You can create a base activity, having above mentioned layout, and extends that activity in all other activities where you want this layout.
Regards, Yuvi

- 1,344
- 4
- 24
- 46
Personnaly, I will do something like that :
1) Create a class which extends from DialogFragment :
public class MyDialogFragment extends DialogFragment{
public static final int DIALOG_TYPE1 = 1;
public static MyDialogFragment newInstance(int dialogType) {
MainDialogFragment frag = new MainDialogFragment();
Bundle args = new Bundle();
args.putInt("type", dialogType);
frag.setArguments(args);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
int type = getArguments().getInt("type");
Dialog result = null;
switch (type) {
case DIALOG_TYPE1:
result = new AlertDialog.Builder(getActivity())
.setTitle("TITLE")
.setMessage("MESSAGE")
.setPositiveButton(android.R.string.ok, null)
.create();
break;
default:
break;
}
return result;
}
}
2) Then in your activities :
DialogFragment dialog = MyDialogFragment.newInstance(MyDialogFragment.DIALOG_TYPE1);
dialog.show(getFragmentManager(), "DIALOG");
3) And you put in a bundle the type of the dialog that the next activity can get it and show it again.

- 1,249
- 2
- 17
- 40