Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

ios - Not getting didReceiveMemoryWarning when app is in the background

I'm noticing that my view controllers aren't getting their didReceiveMemoryWarning methods called when my application is in the background state on the iPad simulator. More specifically, I see the call to applicationDidEnterBackground in my logs, then I hit the "Simulate Memory Warning" button, and then I notice a peculiar lack of any didReceiveMemoryWarning calls.

However, when I bring the application back to the foreground I suddenly get the didReceiveMemoryWarning call, as if it had been queued.

What I'm confused about here is if my application is really in the background, or if it's just flat out suspended. Is there any way to tell in the simulator?

Also, if it is not yet suspended, and really is just in the background, then I would find it silly that I'm unable to process didReceiveMemoryWarning. Because that would then mean that only the foreground application can process memory warnings to free up space, which is of course odd given that the foreground app could be only one of possibly dozens of running apps, and it would make so much more sense if they could all free up memory.

Anyway, the main questions are: why aren't I getting didReceiveMemoryWarning in the background state? And also, am I really suspended? And how do I tell?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you did not start a background task, or do VOIP, location tracking or audio in the background, then your app is suspended after applicationDidEnterBackground. It will not get any notifications. Any notifications are kept around (even those that occur after the app was suspended) and sent to the app when the app goes to the foreground again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...