title: wait for the process to finish to start another process
body: <p>When the user clicks on my button, it performs two functions: sending an SMS and sending an email.</p>
  
  <p>When I click on this button, the SMS is being sent and suddenly the email choose client window pop ups. I want the email client chooser window to show only after completing the SMS sending function. </p>
  
  <p>How should I change my code?</p>
  
  <pre><code>     Button hi= (Button) findViewById(R.id.button1);
       hi.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              sendsms();
              sendemail();
       } 
  
       private void sendemail() {
  
          Intent email = new Intent(Intent.ACTION_SEND);
          email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to1});
          email.putExtra(Intent.EXTRA_CC, new String[]{ to2});
          email.putExtra(Intent.EXTRA_BCC, new String[]{to3});
          email.putExtra(Intent.EXTRA_BCC, new String[]{to4});
          email.putExtra(Intent.EXTRA_BCC, new String[]{to5});
  
          email.putExtra(Intent.EXTRA_SUBJECT, subject);
          email.putExtra(Intent.EXTRA_TEXT, emailmessage);
  
          //need this to prompts email client only
          email.setType("message/rfc822");
  
          startActivity(Intent.createChooser(email, "Choose an Email client :"));
  
  
      }
  
  
      sendsms()
      {
          String receipentsNumber[] = {"111","222","333","444","555"};
  
          for (int i = 0; i &lt; receipentsNumber.length; i++) {
  
              try {
                  SmsManager smsManager = SmsManager.getDefault();
                  smsManager.sendTextMessage(receipentsNumber[i], null, message, null,
                          null);
                  System.ot.println(getApplicationContext(), "SMS Sent to" + " " + receipentsNumber[i], Toast.LENGTH_LONG).show();
  
              } catch (Exception e) {
                  Toast.makeText(getApplicationContext(),
                          "SMS faild, please try again later!", Toast.LENGTH_LONG)
                          .show();
                  e.printStackTrace();
              }
  
          }
      }
  
  });
  </code></pre>