Java 当应用程序来自后台时询问PIN码
我正在尝试实现一个功能,在该功能中,用户每次打开应用程序或来自后台时都会被要求输入PIN。经过搜索,我找到了 我有一个基本的Java 当应用程序来自后台时询问PIN码,java,android,oop,inheritance,Java,Android,Oop,Inheritance,我正在尝试实现一个功能,在该功能中,用户每次打开应用程序或来自后台时都会被要求输入PIN。经过搜索,我找到了 我有一个基本的活动类,REST从中继承。它被称为ParentActivity。我在myParentActivity中实现了Foreground.Listener,并在BecameForeground上重写,并在运行时打开PINActivity。像下面这样 public abstract class ParentActivity extends AppCompatActivity impl
活动
类,REST从中继承。它被称为ParentActivity
。我在myParentActivity
中实现了Foreground.Listener
,并在BecameForeground上重写,并在运行时打开PINActivity
。像下面这样
public abstract class ParentActivity extends AppCompatActivity implements Foreground.Listener {
...
@Override
public void onBecameForeground() {
openSecurityActivity();
}
...
}
然后在所有子类中重写此方法以调用super
@Override
public void onBecameForeground() {
super.onBecameForeground();
}
问题
现在的问题是,每当应用程序出现在前台时,此方法都会运行无数次,因为有子类重写此方法,即使未创建子Activity
。我试着在openSecurityActivity()
中做一个检查,如下所示
synchronized protected void openSecurityActivity() {
if(securityPinRequired) {
if(!isSecurityActivityOpened) {
isSecurityActivityOpened = true;
Intent intent = new Intent(this, FingerprintAndSecurityPINActivity.class);
intent.putExtra(Constants.ASK_SECURITY_PIN, true);
intent.putExtra("isForBackgroundVerification", true);
startActivity(intent);
}
}
}
但它仍然打开了两次。我想不出这个问题。我是否缺少任何基本的OOP概念
感谢您的帮助。谢谢。将android:launchMode=“singleInstance”添加到AndroidManifest.xml文件中是一个非常愚蠢的错误。我在onStart()
中注册了侦听器,但忘记在onStop()
中注销它。我知道它解决了我的问题,但我需要知道它多次打开它的原因+1.将“前台”类实现到应用程序类