12


I've noticed something that happens in every app i develop. It's usually not a concern but in this specific app it would be great if i could "fix" it, if it's even a bug.

Steps to re-produce the issue:

  • Start app , splash screen shows for approx. 3 seconds and app starts.
  • Press home button, app goes to background.
  • Bring app back from background (double clicking home screen and chosing it), shows the splash for half a second or so, and then the app goes back up .

Is it possible to get rid of that splash screen popping up for half a second on the way back from background? Its really a problem for this specific app.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
  • 1
    Make sure that in your app's plist you have `Application does not run in background` set to NO (raw key: [`UIApplicationExitsOnSuspend`](http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23)). Some apps WANT to be "killed" when the user backgrounds them, so they use this key. However, to resume your app you have to allow it to run in background (paused really, doesn't have to actually work in background). – Sam Nov 15 '11 at 22:15
  • It doesn't really change anything, still after returning from background the splash appears for a split second... – Shai Mishali Nov 15 '11 at 22:17
  • Is your code going through `application:didFinshLaunchingWithOptions:` twice (verify with breakpoint or NSLog)? I'm not sure how you would get the splash screen (default.png) to appear everytime you launch the app without using the `UIApplicationExistsOnSuspend` key (which kills app when you background it). Unless... the app inadvertantly is being killed on exit like a SIGABRT in `applicationDidEnterBackground:` or `applicationWillResignActive:`. – Sam Nov 15 '11 at 22:21
  • So you mean i should set it to YES , not NO . (So it would be killed immediately) , but thats not really a solution since i dont want the app to die every time the user closes it... – Shai Mishali Nov 15 '11 at 22:25
  • The default for `UIApplicationExistsOnSuspend` is NO (meaning app is NOT killed when backgrounded). So make sure the key / value pair for this is missing or that it is set to NO so that your app is NOT being killed when backgrounded. - sorry for the caps on no and not, just trying to be as clear as possible. Also, when you background the app your debugging session shouldn't end, so you should be able to set a breakpoint on `applicationWillEnterForeground:` to verify that your session didn't end (app didn't die). – Sam Nov 15 '11 at 22:43
  • I'm not sure of the direction Sam, maybe i'm just not following you but it is set to NO , and the app is not being killed, its kept in the background - how is that related to the issue with the popping splash ? Cheers man :) – Shai Mishali Nov 15 '11 at 23:26

5 Answers5

13

I know that this question is marked an "answered" - but the reality is that the answer was not correct in my case and I want to share.

I initially came to the conclusion that the most accurate answer above was from QueyJoh - "this is something handled by iOS ... Short answer: it's out of your hands."

However after experimenting I managed to locate the issue as being entries in my info.plist file controlling the status bar. Specifically I had entries for "UIStatusBarHidden" and "UIStatusBarStyle".

Removing these entries from my plist file immediately stopped my app from showing the Splash screen when switching away from my app and back again.

Problem solved.

Matthew

10

Well, apparently this question wasn't very clever to begin with :) This "problem" only happens in the Simulator. When Debugging on the device itself, it works as expected.

No harm done. Thanks everyone who tried to help! :)

Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
  • 1
    +1 Not a bad question though. Many people may also encounter this not knowing what's going on until they discover as you did that it is simulator specific. Mark this as the answer. – Sam Nov 16 '11 at 16:33
  • it doesn't let me yet , i will later on :) Thank you Sam! :) – Shai Mishali Nov 16 '11 at 21:51
  • Actually, I have this problem on my 5.1 device just now. Sometimes show splash screen and sometimes doesnt, but didFinishLaunchingWithOptions is not triggered again – Setomidor Sep 25 '12 at 12:30
9

In my experience, this is something handled by iOS (I'm going with experience because I've not seen any documentation about this). If the OS can restore the application state nice and quickly, it'll display a screenshot of its previous state while that state is restored.

However, if something will delay the process, such as the app not being in the background properly yet (such as during rapid task switching), or if something else predictable will delay the startup, then it reverts to the splash screen (instead of the screenshot), to ease the user experience.

Short answer: it's out of your hands.

QueyJoh
  • 146
  • 1
  • 9
  • 1
    You're answering an already-answered question. As I said the problem was in the Simulator, and didn't occur when happening on your device. – Shai Mishali Jul 12 '12 at 09:16
  • 4
    I added the answer because I've seen this occur in my own projects on the device and have had to answer client questions about that, so I felt a more thorough discourse was valuable here for future travellers. – QueyJoh Jul 14 '12 at 01:45
  • Alright, sorry for the downvote. I just usually dont think its good practice to answer an already-closed questions, especially when the answer isn't anything significant ("Its out of your hands"). I appreciate the effort though. – Shai Mishali Jul 14 '12 at 08:36
0

I have this problem too,now I had solve it.The reason is you did too many things in applicationDidEnterBackground ,try to decrease .

gugupluto
  • 31
  • 1
0

Your code to display your splash screen should be in your appdelegate in the didFinishLaunchingWithOptions method. If it is then it only appears when your app actually starts up, not when it returns from the background.

Use something like this (I know it uses the old animation code but I 'm sure you can update it to blocks if you need to)...

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    splashView.image = [UIImage imageNamed:@"Default.png"];

    [myWindow addSubview:splashView];
    [myWindow bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    [UIView commitAnimations];

and then create a method called startupAnimationDone...

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

    [splashView removeFromSuperview];

    [splashView release];
}
Hiren
  • 12,720
  • 7
  • 52
  • 72
amergin
  • 3,106
  • 32
  • 44
  • 1
    I think @Shai Mishali is referring to the "Default.png" file that gets displayed while the app is coming to the foreground. Unfortunately it is not possible to change this behaviour and whether the image gets shown or not when your app is becoming active again will depend on a number of factors but from what I can tell it is mainly what memory you have available at the time. – Rog Nov 15 '11 at 21:46
  • 1
    I tried doing something like this, but the problem is if you don't specify a splash screen you will have a black screen displayed until the app is ready , and only then the splash will be shown. Could i somehow "cancel" the default splash so there won't be a black screen on launch? – Shai Mishali Nov 15 '11 at 21:48
  • what you can do is to grab a copy of the screen just before your app goes to the background in applicationWillResignActive, rename default.png to something else and rename this grabbed image to default.png - I'd imagine this is what reading apps like Kobo do when they're about to go into the background. I haven't done this myself so this is only an assumption. Generally I'd imagine that getting your own image up immediately, whatever it is, in applicationDidBecomeActive would be fairly instant so the user wouldn't have to see a black screen. – amergin Nov 16 '11 at 10:35