这是我第一次尝试android服务,所以我有点迷茫。我正在开发一个需要服务始终在后台运行的应用程序。此服务是从主活动中的onclick事件初始化的。要启动该服务,我使用以下代码:
Intent Test = new Intent(this, testService.class);
startService(Test);
在服务中,我基本上有两件事。在onCreate方法中,我初始化了一个计时器,它每隔30分钟打开一个新线程,并检查服务器是否有新数据。在onStart方法中,我注册了一个接收器。
几个小时后,服务将被终止,垃圾回收器是否可能正在删除该服务?我的怀疑是,我初始化服务的方式仍然绑定到
在connect中,我在连接用户的末尾添加了这段代码:
UIBackgroundTaskIdentifier myLongTask;
myLongTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
// If you're worried about exceeding 10 minutes, handle it here
}];
我使用UnityWebRequestAssetBundle.GetAssetBundle下载位于远程服务器上的资产包。虽然在安卓上一切正常,但当最小化应用程序(或设备进入睡眠状态)时,下载会在iOS上停止。
当我再次将应用放在前台时,XCode显示了以下日志:
-> applicationWillResignActive()
-> applicationDidEnterBackground()
2020-03-08 08:37:51.571235+0100 app[3852:2943256] Can't end BackgroundTask: no background t