title: Make a method call as soon as back button has been pressed (Android)
body: <p>In a given activity, an AlertDialog takes the user into WiFI settings. Then, the user presses the back button to return to said activity. </p>
  
  <p>However, as soon as the back button has been pressed I need to make a method call. Please note that I cannot simply add the method after the following code in the activity, as this will impact the time the user has to interact with the AlertDialog instance.</p>
  
  <p><strong>The method call needs to happen as soon as the back button has been pressed form the WIFI settings menu</strong>. Please inform me of how I can implement this.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>alertDialog.setPositiveButton("Settings", new dialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
            startActivity(intent);
           }
       });
  </code></pre>