What happens to an app when you leave it, why the OS kills it, and what must survive. Learn the app lifecycle on iOS and Android, how to test background and restore scenarios, and hunt bugs in a banking app.
40–55 min intermediate Mobile
Your progress
Daniel is booking a train ticket. Halfway through the passenger form, he switches to his email to copy a booking code. He replies to a message, checks a map, takes a photo. Ten minutes later he goes back to the train app, and it opens on the home screen. The form is empty. The seat he picked is gone. He books with a competitor instead.
On the developer’s brand-new phone with nothing else running, the app always came back perfectly. On Daniel’s three-year-old phone, the OS had quietly killed it to free memory. Nobody had tested that.
Part Not started
Why it matters
People don’t use apps in one long session. They jump between apps dozens of times an hour. Every time they leave, your app moves to the background, and from that moment the OS decides what happens to it: keep it, freeze it, or kill it.
Background and foreground bugs are some of the most common mobile bugs because:
Developers rarely see them. Fast test phones with lots of memory almost never kill apps.
They depend on time. “Come back after 5 seconds” and “come back after 2 hours” are completely different tests.
They touch privacy and security: what’s visible in the app switcher, and whether an expired session is handled.
Check this part
Why do developers rarely see background and foreground bugs?
On a new phone with plenty of memory the app is almost never killed, so the restore path is never exercised.
Are "come back after 5 seconds" and "come back after 2 hours" the same test?
These bugs depend on time: a longer gap can mean a killed app, stale data or an expired session.
Users jump between apps all the time, and once your app is in the background the OS decides whether to keep, freeze or kill it.
App switcher open, Control Center pulled down, an incoming call screen on top
Background
No
Briefly
You just pressed Home
Suspended
No
No, frozen in memory
A few seconds after leaving
Terminated
No
No, removed from memory
The OS killed it, or you swiped it away
iOS names the states exactly like the table: Not running → Inactive → Active, then Background → Suspended when you leave.
An app gets a few seconds in the background to save its work (up to about 30 seconds if it asks for extra time). Then it’s suspended, unless it uses an approved background mode (audio, navigation, calls, background downloads).
A suspended app gets no warning when it’s terminated. That’s why it must save state when going to the background.
If the user force-quits an app from the app switcher, iOS throws away its saved screen state, and system background transfers for that app are canceled.
An Android screen is created, started and resumed (visible and active), then paused and stopped when you leave.
Dev note
These are the activity callbacks: onCreate → onStart → onResume, then onPause → onStop.
A stopped app’s process is cached: kept in memory but not doing anything. When memory runs low, Android kills cached processes, starting with the least recently used.
When the process is killed, the screen’s saved instance state survives. When the user comes back, Android recreates the screen and the app should restore it as if nothing happened.
OEM battery savers on some brands (Xiaomi, Huawei, OnePlus, Samsung “sleeping apps”) kill background apps far more aggressively than stock Android.
Why does the OS kill apps?
Memory: another app (often the camera or a game) needs RAM, so the OS frees it by killing background apps.
Battery: iOS and Android limit background work to save power. Android’s Doze and App Standby, plus manufacturer battery optimizations, can stop apps completely.
Updates and restarts: an app update or a phone restart terminates everything.
Press the actions below and watch the app move between states. The panel explains what the app should do at each step, which callbacks the developer gets, and what must survive. Switch between iOS and Android names at the top.
Lifecycle state machine
Press an action and watch the ShopCo app move between states.
Away from the app: 0 min
Start here
ShopCo is not running yet. Press Open to launch it, then try the other actions. The diagram shows the lifecycle state, the phone shows what the user sees.
The app should
Each step lists what the app must do or preserve at that moment.
Test idea
Follow the path a real user takes: open, browse, leave, come back later.
Callbacks the developer sees (iOS)
None yet
9:41
Messages
Photos
Mail
ShopCo
Music
Podcasts
Notes
Settings
State
Not running
In memory
No
Runs code
No
Check this part
You press Home. A few seconds later the app is in memory but runs no code. Which state is it in?
After a short time in the background the OS suspends the app: it stays in memory but is frozen until the user returns (or the OS kills it).
The OS killed the app in the background to free memory. The user did not swipe it away. What should happen when they reopen it?
From the user's point of view the app was never closed. State restoration should bring them back to where they were.
The states an app moves through, why the OS kills background apps, and why users still expect to return to the same screen.
Part Not started
Background tasks
Some work must continue after the user leaves. Each type has its own rules and its own bugs.
Task
Example
How it keeps running
What to test
Downloads / uploads
Offline maps, a podcast, uploading an ID photo
The app hands the transfer to the system, which keeps it going
Leave during transfer: does it finish? Is progress correct on return? What if the network drops?
Location
Running tracker, delivery driver app
Background location permission, usually a visible indicator
Lock the phone for 10 minutes: is the route complete, without gaps?
Music and audio
Spotify, audiobooks
Background audio mode / media notification
Lock screen controls, headphones, calls while playing
Background refresh
News app showing fresh articles on open
The system wakes the app now and then (iOS calls it Background App Refresh). It runs when the system decides
Turn Background App Refresh off: does the app still work and refresh on open?
Push notifications
“Your order has shipped”
Delivered by Apple / Google, not by the app
Tap them with the app in foreground, background and killed
Dev note
Transfers: a background URLSession on iOS, WorkManager or a foreground service on Android. Refresh: Background App Refresh on iOS, WorkManager on Android.
Check this part
Who delivers push notifications to the phone?
Push notifications are delivered by Apple or Google, not by the app, so they arrive even when the app is not running.
Besides background work succeeding, what else should you test?
Battery savers, Doze and user settings can delay or stop background work at any time.
Downloads, location, audio, background refresh and push notifications each keep running in their own way, and none of it is guaranteed.
Part Not started
What to test
Leaving and coming back
Switch apps (via the app switcher, and via a notification from another app) and come straight back.
Go Home and return after different gaps: 5 seconds, 5 minutes, 1 hour, the next morning. Each gap catches different bugs.
Kill the app from the app switcher, then reopen. Expect a fresh start, but saved data (cart, login, settings) must still be there.
Simulate the OS killing the app (see the tools section) and reopen. Expect to land on the same screen with typed data restored.
Use the phone heavily in between: open the camera, a game and a few other apps, then come back. This creates real memory pressure.
Navigates to the target (or shows an in-app banner first)
Background / suspended
Resumes and navigates to the target
Killed / not running
Cold starts directly on the target (after login if needed), with a sensible Back
Privacy in the app switcher
The app switcher shows a snapshot of each app’s last screen. Anyone looking at the phone can see it. Banking, health, password and messaging apps should blur it or cover it with the app logo. Open the app switcher on every screen that shows personal data and look closely.
Check this part
In which app states must tapping a push notification open the right screen?
All three are different paths. The killed (cold start) path is the one most often broken.
A banking app shows the account balance in the app switcher. What kind of issue is this?
Anyone looking at the phone can see the snapshot. Sensitive apps should blur or cover it.
A banking app's session expired while it was in the background. What should happen when the user returns?
The app should check the session on return, not show stale personal data and then fail with a vague error.
Leave and come back after different gaps, check what must survive, handle stale data and expired sessions, and look at the app switcher.
Part ProNot started
Common bugs
#
Bug
What you see
Typical severity
1
State lost after OS kill
Back on the home screen with an empty form or empty cart
High
2
Sensitive data in the app switcher
Balance, card number or messages visible in the snapshot
High (privacy)
3
Stale data on return
Old balance, prices or stock after hours in the background
Medium–High
4
Expired session not detected
Logged-in screen with old data until an action fails with a vague error
High
5
Notification opens the wrong screen
Tapping “Your order shipped” opens the home screen when the app was killed
Medium
6
Background upload or download stops
Progress stuck at 40% forever, no error, no retry
High
7
Crash on restore
App crashes when reopened after being killed in the background
Critical
8
Duplicate screens
Each notification tap stacks another copy of the screen; Back has to be pressed many times
Low–Medium
9
Location gaps
A run or delivery route has straight lines where tracking stopped in the background
High (for that app)
10
Media restarts from zero
A podcast or video starts over after a warm resume
Medium
Find the bug
Northbank is a banking app with six lifecycle bugs. Use the device controls to send it to the background, wait, let the OS kill it, open the app switcher and send a push notification. The phone’s clock moves when you wait. Watch the network log: what the app does (and doesn’t) request is a big clue.
🐞 Bug hunt: Northbank banking app
This demo has 6 hidden bugs. Explore it like a tester, then check your findings.
Found0/6
9:41
Good morning,
Alex
Main account · ••• 2210
€4,812.50
Updated 9:41
Recent
Coffee Corner−€3.80
City Rent Co−€950.00
FreshMart−€42.15
Device controls
Northbank: in the foreground. Tap its icon on the Home screen to open it.
Network log
Requests the app sends appear here…
What happened
Use the device controls to send the app to the background…
1
Hint: On the accounts screen, open the App switcher and look at the Northbank card.
Account balance is visible in the app switcher
The snapshot shows the full balance and recent transactions. Anyone glancing at the phone can see them. Expected: the app covers or blurs its content before the snapshot is taken (iOS: when the app resigns active; Android: FLAG_SECURE or a privacy overlay).
2
Hint: Go Home, Wait 2 min, then reopen the app. Compare the "Updated" time with the clock, then tap refresh.
Stale balance after returning from the background
The app shows the old balance and "Updated 9:41" while the clock says 9:43, and the network log shows no request on return. Refreshing reveals a €250 payment that arrived meanwhile. Expected: the app refreshes data (or at least checks it) when it returns to the foreground after a while.
3
Hint: Fill in a transfer, Go Home, tap OS kills app, then reopen Northbank from its icon.
Transfer draft lost after the OS kills the app
The app cold-starts on the accounts screen and the recipient, amount and reference are gone. The user never closed the app, so they expect to return to the transfer. Expected: the screen and draft are restored from saved state. (After a user swipe-away, a fresh start is acceptable.)
4
Hint: Compare: Send push and tap it with the app in the background, then again after OS kills app.
Notification opens the home screen when the app was killed
In the background, tapping opens the €120 transaction correctly. When the app was not running, it cold-starts on the accounts screen and ignores the notification. Expected: the transaction details open in both cases.
5
Hint: Start the ID upload in Verify ID, Go Home before it finishes, then come back.
Upload silently stops in the background
The progress bar is stuck forever and still says "Uploading…". The network log shows the request was aborted, but the user is never told. Expected: the upload continues in the background (background transfer / WorkManager), or at least fails visibly and offers a retry.
6
Hint: Go Home, Wait 30 min, reopen the app, then try to refresh or send a transfer.
Expired session still shows the logged-in screen
The server ended the session after 15 minutes, but the app still shows the balance. The first action fails with a vague "Something went wrong" and a 401 in the network log, and the user is stuck. Expected: on return, the app checks the session and shows the login screen right away, hiding personal data.
Check this part
Which of these bugs is typically the most severe?
A crash on restore is critical: the user cannot get back into the app at all.
Tapping a push notification works when the app is in the background, but opens the home screen when the app was killed. What should you do?
"Notification opens the wrong screen" is a common bug. The notification must open its target in every state.
Lost state, leaky snapshots, stale data, missed session expiry, wrong notification targets and stalled uploads, then a banking app to hunt in.
The rest of this lesson is in Bugwise Pro
The last parts of every lesson are part of Bugwise Pro. Sign in to unlock them if you have it.
Without a computer you can still do the most important test: on Android, turn on Don’t keep activities in Developer options; on iPhone, open several heavy apps and come back later. The adb and xcrun simctl commands below are faster and more exact, but optional: adb is set up in adb Basics, and xcrun simctl comes with Xcode (see Simulators and Emulators).
Simulate the OS killing your app (keeps saved state):
Open the app, go to a screen with typed data, press Home.
Run adb shell am kill com.example.app. It only kills the app if it’s in the background, just like the system would.
Reopen the app from the app switcher (Recents). It should restore the screen and the data.
“Don’t keep activities”: in Settings › System › Developer options, turn on Don’t keep activities. Every screen is destroyed as soon as you leave it, so any screen that doesn’t save its state shows the bug immediately. Also try Background process limit › No background processes. Turn both off again when you’re done, as they make the whole phone behave strangely.
Other useful commands:
adb shell am force-stop com.example.app # like "Force stop" in Settings (state is NOT kept)adb shell am start -W -a android.intent.action.VIEW -d "shop://order/4521" com.example.app # deep linkadb shell dumpsys deviceidle force-idle # push the device into Dozeadb shell dumpsys deviceidle unforce # leave Doze
Simulate the OS killing your app (keeps saved state): Apple’s recommended way is to run the app from Xcode, press Home in the app so it goes to the background, then click Stop in Xcode. Relaunch it: state restoration should bring you back. Don’t swipe it away in the app switcher for this test, because a force-quit deletes the saved state on purpose.