If different radio buttons are clicked, only the value of the last one will be saved his is the part 2 of a quiz application that I created. The first part works fine, but on this part, when I click a radio button, the score will just stack up. For example, if I click Radio Button 2, and then click Radio Button 3, the score will become 3 instead of just 2.
If I try to move the getAnswer() to the OnClickListener in the button, If I click a radio button it won't proceed to the next activity unless I click a different radio button. 
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_part2);


   firebaseAuth = FirebaseAuth.getInstance();
   firebaseDatabase = FirebaseDatabase.getInstance();

   gadChoice1 = (RadioButton)findViewById(R.id.part2Choice1);
   gadChoice2 = (RadioButton)findViewById(R.id.part2Choice2);
   gadChoice3 = (RadioButton)findViewById(R.id.part2Choice3);
   gadChoice4 = (RadioButton)findViewById(R.id.part2Choice4);
   btnNext = (Button)findViewById(R.id.btnNext);

   getAnswer();

   DatabaseReference myRef = firebaseDatabase.getReference(firebaseAuth.getUid()).child("test");
   myRef.addValueEventListener(new ValueEventListener() {
       @Override
       public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
UserHistory userHistory = dataSnapshot.getValue(UserHistory.class);
anxHistory = userHistory.getAnx();
depHistory = userHistory.getDep();

       }

       @Override
       public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(Part2.this, databaseError.getCode(), Toast.LENGTH_SHORT).show();
       }
   });

   btnNext.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {


anxValue = anxHistory + anx;

final DatabaseReference myRef = firebaseDatabase.getReference(firebaseAuth.getUid()).child("test");

myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
HashMap<String, Object> result = new HashMap<>();
result.put("anx", anxValue);
myRef.updateChildren(result);
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getMessage());
}
});

if(dep > anx){
Intent myIntent = new Intent(Part2.this, Part3.class);
startActivity(myIntent);
finish();
}else if (anx > dep){
Intent myIntent = new Intent(Part2.this, Part3.class);
startActivity(myIntent);
finish();
}
       }
   });   }

   private void getAnswer() {
   radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
   radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

       @Override
       public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.part2Choice2) {
anx++ ;
} else if (checkedId == R.id.part2Choice3)  {
anx = anx + 2 ;
}
else if (checkedId == R.id.part2Choice4) {
anx = anx + 3;
}


       }
   });

   }

I expect the output to be the value of the radio button selected and not the sum of the radio button that I have clicked. For example, if I clicked Radio button A (0), Radio Button B (1), Radio Button C(2), the output that I will record is 2. 

You can't handle it inside the the onCheckedChanged because it will increments every time you change the selected one. You can test on the selected one when clicking btnNext : 
int selectedItem = radioGroup2.getCheckedRadioButtonId();
if (selectedItem == R.id.part2Choice2) {
    anx++ ;
} else if (checkedId == R.id.part2Choice3)  {
    anx = anx + 2 ;
}
else if (checkedId == R.id.part2Choice4) {
    anx = anx + 3;
}