code:
@Override
public void onBackPressed() {
println("by by..");
if(android.os.Build.VERSION.SDK_INT>=16 && android.os.Build.VERSION.SDK_INT<21){
getActivity().finishAffinity();
} else if(android.os.Build.VERSION.SDK_INT>=21){
getActivity().finishAndRemoveTask();
}
}
Works on Actual Android devices 2020.