[英]Activity of my app goes into background sometimes after I turn off the screen
I am running Camera as a service attached to an activity. 我正在将Camera作为附加到活动的服务运行。 There are other services such as upload and Firebase are running along with the camera service.
还有其他服务(例如上载和Firebase)与摄像头服务一起运行。 Now my requirement is to keep the service running after I turn off the screen.
现在,我的要求是在关闭屏幕后保持服务运行。 I am acquiring PARTIAL_WAKE_LOCK too.
我也正在获得PARTIAL_WAKE_LOCK。 The services run perfectly for the initial 10 or 12 minutes.
该服务在最初的10或12分钟内可以完美运行。 After that, the app stops sending any logs to ADB.
之后,该应用程序停止将任何日志发送到ADB。 In the device, the app goes to the background by itself.
在设备中,该应用程序会自行进入后台。 Not even onPause or onDestroy is logging anything.
甚至onPause或onDestroy都不记录任何内容。 The logs just stop coming to Android Studio.
日志只是停止进入Android Studio。 For resuming the normal functioning I have to manually open the app again,
要恢复正常运行,我必须再次手动打开该应用,
These are the things that I have already tried, 这些是我已经尝试过的东西,
1.Given permission of acquiring PARTIAL_WAKE_LOCK. 1.获得获得PARTIAL_WAKE_LOCK的许可。
2.Setting android:largeHeap="true" 2.设置android:largeHeap =“ true”
3.Foreground services 3,前台服务
According to Doze mode documentation it ignores wake locks. 根据打ze模式文档,它会忽略唤醒锁。
Also starting from Android Pie it is impossible to gain camera access from background app. 同样从Android Pie开始,无法从后台应用程序获得相机访问权限。
Also according to android developer guidelines you must free camera, when you app is paused, because it will block all other apps. 另外,根据android开发人员指南,当您的应用暂停时,您必须释放相机,因为它会阻止所有其他应用。
onSaveInstanceState function should be called in these situations, check with you and if its called then open the activity again with the delay. 在这种情况下,应调用onSaveInstanceState函数,并与您检查是否被调用,然后在延迟的情况下再次打开活动。
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
try {
Intent intent = new Intent(getBaseContext(), YourActivity.class);
startActivity(intent);
finish();
} catch (Exception ex) { }
}
}, 200);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.