Start Compiled App from Beginning

I’ve done an app that I sideload onto school iPads from Xcode. Is there any way to have the app restart when the user closes it using the Home key on the iPad? It continues from where the last user left off which is confusing to the next user.

thanks,

dave

Not that I know of, because we don’t have a way of knowing in the Codea runtime when our app has gone into the background. It would be useful for other things too, such as pausing the physics simulation. You could request it in the issue tracker. A new global function called appBackgrounded / appWillBackground or whatever, allowing you to do whatever you need to do before your app disappears (in your case reset() or close())

Meantime, I guess your alternatives are a big friendly “Goodbye!” button that triggers close(), or a 4-finger swipe up, and then swipe the app up off the screen (force close).

@DaveW You could try something like this. When a program goes into the background, it stops running. When it’s started again, the difference between h and the current time will be large and you could then do some kind of a restart.

function setup()
    h=os.time()
end

function draw()
    background(0)
    if os.time()-h>5 then
        print("restart")
    end
    h=os.time()
end

Assuming there is a time delay between users, you could program Codea to detect the gap (by continuously storing current time), and if it exceeds X minutes, to ask for a login.

@DaveW Here’s a better example then what I show above.

displayMode(FULLSCREEN)

function setup()
    h=os.time()
    count=0
end

function draw()
    background(0)
    fill(255)
    checkForRestart()
    text(count,WIDTH/2,HEIGHT/2)  
    count=count+1  
end

function checkForRestart()
    if os.time()-h>2 then
        setup()        
    end
    h=os.time()    
end

Thanks for the good suggestions but there may not be much time between users. These are elementary students and things happen quickly. It looks as if this can be done in Xcode (about which I know barely enough to do the compile). I found this: “Set the app’s info.plist key: UIApplicationExitsOnSuspend to True.” Does anyone have experience with this? I have to get back to school to use the Mac to try it. I do have experience with editing plist to allow non-secure Web sites to be accessed using openURL. Thanks.

@DaveW My example above is set for 2 seconds. It can be set to any value that you think will work.

0.5 seconds is probably plenty

I think @Ignatz and @dave1707 suggestions sound great, don’t know why I didn’t think of that.

However, you could also try (haven’t tested this)

  • open the Info.plist file in Xcode (the one in the root of the project, not the one in the Codea folder)
  • Press + on the top-left cell (the root, next to where it says “Information Property List”)
  • Select a category from the dropdown. I can’t see UIApplicationExitsOnSuspend, but there is Application does not run in background, set the value of this to YES from the dropdown

@dave1707 and @Ignatz I didn’t think about being able to set the time out to be that short. 0.5 should do it. These kids try something then immediately hand the iPad to someone else. Thanks a bunch!