, if you want to open the warning dialog after receiving a response in onRecieve, and then add the following code to OnRecieve, here I am warning the dialog after clicking the notification.
Intent intent = new Intent(mainContext,HomeActivity.class).putExtra("fromNotificationClick",true); PendingIntent pIntent = PendingIntent.getActivity(mainContext, (int) System.currentTimeMillis(), intent, 0);
, then in your home life add the following code to onCreate,
boolean fromNotificationClick=false; Bundle extras=getIntent().getExtras(); if(null!=extras) fromNotificationClick=extras.getBoolean("fromNotificationClick"); if(fromNotificationClick){ alert(); }
Finally, add the code for the alert method.
public void alert() { new AlertDialog.Builder(HomeActivity.this).setIcon(R.drawable.help).setTitle("Alert") .setMessage("Are you sure....") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getBaseContext(), "Coming to help", Toast.LENGTH_SHORT).show(); } }).setNegativeButton("No", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getBaseContext(), "NO...", Toast.LENGTH_SHORT).show(); } }).show(); }
Ashpaq May 23 '17 at 7:33 2017-05-23 07:33
source share