1

The 2nd activity Launches multiple times after the user has been successfully authenticated. I have called the intent inside a Volley get-Request which is further inside the on success method of a Firebase sign in with Email and Password Request.

I have tried adding the flag FLAG_ACTIVITY_REORDER_TO_FRONT as suggested here,however it still launches multiple times.

Here is the code where I think the error could be (these are just parts of the code not the entire code)

auth.signInWithEmailAndPassword(u, p)
   addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
   @Override
   public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {
                     getdata();
                      }
          }

public void getdata() 
  {
   JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,URL, null,
      new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

          //Getting data from response

          Intent intent = new Intent(Login.this,Activity2.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
          startActivity(intent);
          finish();
    }
  requestQueue.add(jsonObjectRequest);
    }

How can I ensure that Activity2 Launches only once? Also could you explain why this is happening?

Aditya Kurkure
  • 422
  • 5
  • 19

0 Answers0