您好,我发现了 2 个我想解决的内存泄漏。
收到回调后onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result)
,我想setResult()
调用finish()
ActivityB 回到 ActivityA。
尽管这确实可以正常工作,但在调用finish()
.
以下是重现内存泄漏(ActivityB)的相关代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);;
BiometricPrompt biometricPrompt = biometricPromptInstance();
biometricPrompt.authenticate(buildPromptInfo());
}
private BiometricPrompt biometricPromptInstance(){
Executor executor = ContextCompat.getMainExecutor(this);;
BiometricPrompt.AuthenticationCallback callback = new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
}
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
setResult(RESULT_OK);
//Causing leak: ////////////////////////////////////////////////
finish();
/////////////////////////////////////////////////////////////////
}
@Override
public void onAuthenticationFailed() {
}
};
return new BiometricPrompt(this, executor, callback);
}
private BiometricPrompt.PromptInfo buildPromptInfo(){
return new BiometricPrompt.PromptInfo.Builder()
.setTitle("Login")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Cancel")
.build();
}