我在我的应用中使用了儿童锁。当应用程序恢复时,我可以调用密码活动来确认PIN。我如何在Android应用程序中实现应用程序生命周期。
谢谢。
答案 0 :(得分:2)
最后,我解决了我的问题。
我刚使用全球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;
}
}