I want to write a method to calculate the age from the birth date, is the logic correct and how to write it in android Java:
public int calculateAge(String b
private String getAge(int year, int month, int day){
Calendar dob = Calendar.getInstance();
Calendar today = Calendar.getInstance();
dob.set(year, month, day);
today.set(today.get(Calendar.YEAR), today.get(Calendar.MONTH) + 1,
today.get(Calendar.DATE));
int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)) {
age--;
}
Integer ageInt = new Integer(age);
String ageS = ageInt.toString();
return ageS;
}