title: How to call all activity onDestroy() when MainAcitivty call onDestroy()?
body: <p>I made two activities for the test.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          ...
          Button button = findViewById(R.id.button);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  startActivity(new Intent(MainActivity.this, SubActivity.class));
              }
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
      }
  }
  </code></pre>
  
  <p>This button in MainActivity can start SubActivity.</p>
  
  <pre><code>public class SubActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          ...
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
      }
  
      @Override
      public void onBackPressed() {
          startActivity(new Intent(SubActivity.this, MainActivity.class));
      }
  }
  </code></pre>
  
  <p>When in SubActivity, press back button, it doesn't call <code>onDestroy()</code> in <strong>SubActivity</strong> class and start MainActivity. What I want to do is, How to call SubActivity <code>onDestroy()</code> when I finish the MainActivity? It doesn't call SubActivity <code>onDestroy()</code> when I press the back button in MainActivity. Is there any solution like using <code>Intent.FLAG_ACTIVITY</code>?</p>