It is quite easy. All you have to do when going back to Activity A from Activity B is to tell Activity A that you're coming from Activity B.
In your onBackPressed()
, replace startActivity(new Intent(ActivityB.this, ActivityB.class));
with the following code :
Intent i = new Intent(ActivityB.this, ActivityB.class);
i.putExtra("from", "activityB");
Then, in Activity A, just check for this extra before displaying the dialog box :
Intent thisIntent = getIntent();
if (thisIntent != null && thisIntent.getExtras() != null
&& thisIntent.getExtras().containsKey("from")
&& thisIntent.getExtras().getString("from").equals("activityB")) {
// Coming from Activity B : nothing
} else {
// Display your dialog box
}