简体   繁体   English

Application.onCreate被多次调用

[英]Application.onCreate called more than once

I have an application where I extend Application class and override the onCreate method. 我有一个应用程序,可以在其中扩展Application类并覆盖onCreate方法。
In my onCreate, I schedule a service to run every 5 minutes using AlarmManager. 在onCreate中,我计划使用AlarmManager每5分钟运行一次服务。
In the logs, I see that onCreate get's called again after a while as though the application was restarted / recreated. 在日志中,我看到一段时间后好像重新启动/重新创建了应用程序,再次调用了onCreate get。
this ends up with my service not being synchronized with the first execution. 最终导致我的服务未与第一次执行同步。
Is there a way to prevent this and to guaranty code in Application's onCreate will execute exactly once (assuming of course the application wasn't explicitly closed by the user)? 有没有一种方法可以防止这种情况发生,并且可以保证Application的onCreate中的代码仅执行一次(假设用户没有明确关闭该应用程序)?

Thanks 谢谢

onCreate() on your Application is called as part of starting up your process. 在您的Application上调用onCreate()是启动过程的一部分。 If you are seeing it called several times in the logs, that is because your process was terminated in between runs. 如果您在日志中看到它多次调用,那是因为您的进程在两次运行之间被终止了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Application.onCreate() 未在调试版本中调用 - Application.onCreate() not called in debug build 在Application.onCreate代码之前调用NotificationListenerService - NotificationListenerService called before Application.onCreate code 确定调用Application.onCreate()的进程 - Determine by which process Application.onCreate() is called Android Activity::onCreate 在 Application.onCreate 之前调用 - Android Activity::onCreate called before Application.onCreate 在Application.onCreate()上的BroadcastReceiver - BroadcastReceiver on Application.onCreate() 在BroadcastReceiver.onReceive(..)之前是否会调用Application.onCreate(Bundle)? - Will Application.onCreate(Bundle) be called before BroadcastReceiver.onReceive(..)? 是否有Android注释要求在Application.onCreate期间调用方法? - Is there an Android annotation to require that a method be called during Application.onCreate? 由于应用onCreate()多次调用,M上但不是L上的静态变量重新初始化 - static variable reinitialization on M but not on L due to Application onCreate() called more than once MQTT在多次调用onCreate时创建多个连接 - MQTT Creates Multiple connections when onCreate is called more than once 为什么 ContentProvider.onCreate() 在 Application.onCreate() 之前被调用? - Why does ContentProvider.onCreate() get called before Application.onCreate()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM