自定义 PIN 的应用程序生命周期 Android

Application life cycle for Custom PIN Android

我在我的应用程序中使用了儿童锁。当应用程序恢复时,我可以调用密码 activity 来确认 PIN。我如何在 android app.

中实现应用程序生命周期

谢谢。

终于,我解决了我的问题。

我刚刚使用了全局 Activty 并检查了 activity 是否为 运行。

class CryptActivity extends AppCompatActivity {

public String TAG = "HII";
public boolean wasPaused = false;

@Override
protected void onResume() {
    super.onResume();

    Log.e(TAG, "onResume: RESUME " + wasPaused);

    if (wasPaused) {
        showLockScreen();
        wasPaused = false;
    }

}

private void showLockScreen() {

    SessionManager session = new SessionManager(getApplicationContext());

    if (session.getPin() != -1)
        startActivity(new Intent(getApplicationContext(), PasswordActivity.class));

}

@Override
protected void onPause() {
    super.onPause();

    if (isApplicationInBackground()) {
        wasPaused = true;
    }

    Log.e(TAG, "onPause: PAUSE" + wasPaused);
}

private boolean isApplicationInBackground() {
    final ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    assert manager != null;
    final List<ActivityManager.RunningTaskInfo> tasks = manager.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        final ComponentName topActivity = tasks.get(0).topActivity;
        return !topActivity.getPackageName().equals(getPackageName());
    }
    return false;
}

}