为什么 activity 不能正常恢复?

Why doesn't the activity resume properly?

我试图让程序在按最右边的按钮查看打开的应用程序或使 phone 进入睡眠状态后调用 onPause 和 onStop 后正确恢复。我不熟悉正确的电话是什么。我已经查找了一些关于此的信息,但我发现的只是人们说在 onPause 中调用 super.onPause 并在 onResume 中调用 super.onResume 然后编写我的代码。然而,这段代码不是我的,并且在恢复时崩溃并出现错误:

java.lang.RuntimeException: Unable to resume activity {org.tensorflow.lite.examples.detection/org.tensorflow.lite.examples.detection.DetectorActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.startPreview()' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.startPreview()' on a null object reference

代码可在以下位置找到: https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/LegacyCameraConnectionFragment.java


关于这一切,我有 两个 个问题:


主要 activity 代码 link: https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/CameraActivity.java

由于某种原因,我在问题中所做和提及的更改并没有解决问题。我想这与调用 onStop 后未正确设置回调或新的后台线程更改某些内容有关?

为了修复它,我添加了

textureView.getSurfaceTextureListener().onSurfaceTextureAvailable(textureView.getSurfaceTexture(), textureView.getWidth(), textureView.getHeight());

在 Legacy 中的第 152 行之前...java 文件。