As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!







Sending an App to the Background

by Jon (Updated on 2015-10-17)


  • Introduction
  • Use the Focus Event
  • Best Practice - Pause the Game
  • FAQ: Why does my app restart from scratch?


Many modern mobile devices support some form of multitasking -- the ability to switch between several apps by sending the currently active app to the "background."

Stencyl provides a simple but effective way of performing logic when an app enters and leaves the background.

Use the Focus Event

The Focus event (under Add Event > Input) not only works on web/desktop games, but it also works the same way on mobile games.

Focus Event

Focus Event Block

The Focus event will happen in two cases.

1) Losing Focus

Happens just before the game is sent to the background.

2) Regaining Focus

Happens just after the game resumes but before anything else happens to it.

Best Practice - Pause the Game

When would you use the Focus event in a mobile game?

It’s a good idea to pause a game when it enters the background. When that happens, it's also a good idea to display some appropriate graphics to indicate the game's paused status.

Losing Focus


Why is this a good idea? Imagine that a player switched away from the app but was left in a situation where he'd get hit within seconds. If the app weren't paused, the player would likely be too slow to react and would get frustrated.

FAQ: Why does my app restart from scratch?

Multitasking on iOS or Android doesn't work the same way as it does on a PC or Mac. If the amount of free memory on the device is too little, the device will stop a backgrounded app to free up memory, so that it can support the task at hand. This causes the game to start from scratch - likely lost progress for the player.

If you wish to support true multitasking, we recommend that you save the game upon losing focus and offer to load the saved game if you detect that the game has restarted (similar to the "Quick Save" option in recent Mario games).

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!


Losing Focus = Pause
Gaining Focus = Unpause
Pretty useful (l guess)

0 3 years, 10 months ago
Updated the article and yeah, it was backwards.
0 8 years, 7 months ago
@ Jon... Don't you have this backwards??

1) Gaining Focus

Fired just before an app is about to go to the background.

2) Losing Focus

Fired just after an app is resumed but before anything else happens to it.

3 10 years, 3 months ago

Sign In to Comment