Question: I have a `main activity A` -> `call activity B` -> `call activity C` -> `call activity D`. 

Activity is called by `startActivity(intent).`
`Activity D` have a "Close" button. 

How to I notify to `Activity A` when hit "close" button on `Activity D`?

Any help is appreciated.

Answer: 
```
   //* start the activity with enum defined int activity D to identify your activity
   startActivityForResult(intent, DActivity.D_REQUEST_CODE);

  //in your D activity define this
  private static final int D_REQUEST_CODE  = 1;

  //* when the button is clicked to close in your D activity, call this in the button event listner
  setResult(Activity.RESULT_OK, intent);

  //* implement this in your A activity
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {
    if(data==null)return;
    if (requestCode == DActivity.D_REQUEST_CODE) 
    {
      switch (resultCode) 
      {
        case Activity.RESULT_OK:
           //* do something
            break;
        default:
            break;
      }
    }

```
```
    findViewById(R.id.button_close).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(this, Activity_A.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

```

This will work if you are looking to simply show Activity A while clearing the activity stack. If you just want to know when you return to Activity A, you can save status in SharedPrefs as answered above.