nsinvocation
nsinvocation

Reputation: 7637

Keep dialog/activity always on the top

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.

Look at Show, Hide buttons

Upvotes: 3

Views: 3736

Answers (2)

bibu
bibu

Reputation: 1269

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.

Upvotes: 1

Yuvi
Yuvi

Reputation: 1350

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

Upvotes: 3

Related Questions