In my code, when user click on a button, it calls a function.In that function data has to loaded from firebase. On successful of loading, Intent will pass to another activity with some putExtra data.
SharedPreferences pref = getApplicationContext().getSharedPreferences("My_pref", MODE_PRIVATE);
        choice = pref.getInt("language", 0);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if(choice==1)
                {
                    firebase("param1","param2","English");
                }
                if(choice==2)
                {
                    firebase("param1","param2","hindi");
                }
            }
        });
 public void firebase(String files,String titles,String language)
    {
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference(language);
        DatabaseReference myRef1=myRef.child(titles);
        DatabaseReference myRef2=myRef.child(files);
        myRef1.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                language_title = dataSnapshot.getValue(String.class);
                t=1;
            }
            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
            }
        });
        myRef2.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                language_file= dataSnapshot.getValue(String.class);
                f=1;
            }
            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
            }
        });
            if(t==1&&f==1) {
                Intent i = new Intent(getApplicationContext(), caf.class);
                i.putExtra("titles", language_title);
                i.putExtra("files", language_file);
                startActivity(i);
            }
    }
But in that case intent is only passing when I click twice.In single click Intent is not passing. where is the problem?