(模拟)在后台一段时间后重新启动应用程序

时间:2022-09-13 01:24:56

I have an app magazine reader app that downloads list of new magazines from the server. Magazines change once a day. I need to make sure that they are downloaded at least once a day.

我有一个app杂志阅读器应用程序,从服务器下载新杂志列表。杂志每天更换一次。我需要确保每天至少下载一次。

I download magazine when app starts, it can take some time so I always show loading screen. Now, the problem is that when app enters the background, it can stay there for long time and I need to download magazines again if it was more than some period of time. I tried to use applicationWillEnterForeground, start downloading magazines and show loading screen, but it shows app in the state it was at the moment of exiting while it starts up and loading screen shows after second or two, this looks very weird.

我在应用程序启动时下载杂志,可能需要一些时间,所以我总是显示加载屏幕。现在,问题是,当应用程序进入后台时,它可以在那里停留很长时间,如果超过一段时间我需要再次下载杂志。我尝试使用applicationWillEnterForeground,开始下载杂志并显示加载屏幕,但它显示应用程序处于退出时的状态,当它启动并在第二或第二次加载屏幕显示后,这看起来很奇怪。

My question is, what should I do to have loading screen visible after app was for some time in the background? Bet thing would be to kill it after some time period, but I don't think that this possible. Other solution would be to show loading screen before app is resumed from the background, but I don't know how to do that, is it even possible?

我的问题是,在应用程序在后台播放一段时间后,我应该怎么做才能看到加载屏幕?打赌的事情会在一段时间后杀死它,但我不认为这是可能的。其他解决方案是在应用程序从后台恢复之前显示加载屏幕,但我不知道该怎么做,它甚至可能吗?

2 个解决方案

#1


0  

To kill it try:

要杀了它,试试:

    exit(0);

In an app delegate method.... didEnterBackground or Foreground or whatever!

在app委托方法.... didEnterBackground或Foreground或其他!

#2


0  

I'm not saying this is a perfect solution, but have you considered disabling the app running in the background?

我不是说这是一个完美的解决方案,但您是否考虑过禁用在后台运行的应用程序?

(模拟)在后台一段时间后重新启动应用程序

This isn't suitable for every app and it will increase load time, but it's worth mentioning.

这不适合每个应用程序,它会增加加载时间,但值得一提。

#1


0  

To kill it try:

要杀了它,试试:

    exit(0);

In an app delegate method.... didEnterBackground or Foreground or whatever!

在app委托方法.... didEnterBackground或Foreground或其他!

#2


0  

I'm not saying this is a perfect solution, but have you considered disabling the app running in the background?

我不是说这是一个完美的解决方案,但您是否考虑过禁用在后台运行的应用程序?

(模拟)在后台一段时间后重新启动应用程序

This isn't suitable for every app and it will increase load time, but it's worth mentioning.

这不适合每个应用程序,它会增加加载时间,但值得一提。