0

My app listens for an Intent fired by a third party app when an Activity in that app is shown. The Intent is received in a BroadcastReceiver in my app. I want to start an Activity from the BroadcastReceiver which will show as a Dialog over the existing activity (that fired the Intent).

@Override
public void onReceive(final Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, ">>>>>>>>> Action:" + action);

    if ("clover.intent.action.V1_ORDER_BUILD_START".equals(action)) {
        Intent i = new Intent(context.getApplicationContext(), ActiveOrderActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

The Intent clover.intent.action.V1_ORDER_BUILD_START is fired by a different app which my app listens for. When this Intent is fired, an Activity is already open (see the background activity in the picture below).

Now I want to show an Activity in my app as Dialog over the already shown activity, just like the "Add Customer to Order" in the image below.

As shown in the code above, I am starting an Activity from BroadcastReceiver, but when it starts, it comes to foreground and the previous Activity is not shown.

See below for an example of what I want to achieve,

Example UI of what i would like to achieve

Aravindan R
  • 3,084
  • 1
  • 28
  • 44

1 Answers1

1

Maybe you should create

public class MyDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Get the layout inflater
    LayoutInflater inflaterViewObject = LayoutInflater.from(getActivity());
    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View DialogView = inflaterViewObject.inflate(R.layout.dialog, null);
    final AlertDialog Dialog = new AlertDialog.Builder(getActivity()).create();
    Dialog.setView(DialogView);

    DialogView.findViewById(R.id.dialog_YES).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //your YES logic
            Dialog.dismiss();
        }
    });

    DialogView.findViewById(R.id.dialog_NO).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        //Your NO LOGIC
            Dialog.dismiss();
        }
    });

    // return dialog object (later on .show());
    return Dialog;
}

Later you write in your choosen place (in BrodcastReciever)

MyDialog dialogObject = new MyDialog();
dialogObject.show(getFragmentManager(), "tag name for the dialog fragment.");
Jakub S.
  • 5,580
  • 2
  • 42
  • 37