title: Use of finish() and intent FLAGS
body: <p>currently I am working on the login system for my android app. </p>
  
  <p>I have implemented a OTP verification process in a custom BroadCastReceiver. Once the otp is verified an intent is sent from the BroadCastReceiver as below.</p>
  
  <pre><code>    Intent c=new Intent(context.getApplicationContext(), SignInActivity.class);
      if (msgs[0].getOriginatingAddress().equals("+919920678579")) {
          c.putExtra("code", "verified");
          c.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(c);
      } else {
          Log.d("message ", "error, not verified!!");
      }
  </code></pre>
  
  <p>Now this sends data back to signIn activity where I check for a non-null intent</p>
  
  <pre><code> @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sign_in);
          btn=(Button)findViewById(R.id.btn);
          Intent i=getIntent();
          if (i.getStringExtra("code")!=null){
              if (i.getStringExtra("code").equals("verified")) {
                  Toast.makeText(SignInActivity.this, "verified!", Toast.LENGTH_LONG).show();
                  //SHOW SOME UI CHANGES
                   Intent intent=new Intent(SignInActivity.this, MainActivity.class);
                      startActivity(intent);
                      finish();
                  }
              }
  
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  
          SmsManager smsManager = SmsManager.getDefault();
          String phoneNumber = "+919920678579";
          byte[] smsBody = "+919920678579".getBytes();
          // DO NOT CHANGE THIS. IDK WHY ITS NOT WORKING IF REFERENCED FROM INT AND TYPE CAST TO SHORT!!
          short port = 6734;
          smsManager.sendDataMessage(phoneNumber, null, port, smsBody, null, null);
          Log.d("sms ", "sent");
              }
          });
  
      }
  </code></pre>
  
  <p>and my Dispatch / Launcher activity</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      if (ParseUser.getCurrentUser() != null) {
          //TODO: check validity of finish(). Supposed to remove this from backstack
          // Start an intent for the logged in activity
          Log.d("User logged in as ", ParseUser.getCurrentUser().getUsername());
          Intent mainIntent=(new Intent(this, MainActivity.class));
          mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
          mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(mainIntent);
          finish();
      } else {
          // Start and intent for the logged out activity
          Log.d("User ", "sent to signUp");
          Intent signIntent=(new Intent(this, SignInActivity.class));
          signIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
          signIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(signIntent);
          finish();
      }
  }
  </code></pre>
  
  <p>The flow is User clicks on app --> Dispatch Activity (assuming first time user) --> SignInActivity --> Sms is sent and received by broadcastreceiver --> Sends information to signInActivity after veryfing OTP --> Users goes to MainActivity page. At no point I want the user to be able to hit back button and go to the previous activity. I have tried using Intent flags and finish().  BroadCastReceiver sends intent to SignInActivity and not MainActivity cause I want to show an animation/ TOAST which is why I have a code checking for the non-null Intent. But im able to go back to the activities which is very frustrating. Could someone help me out please?</p>