# \[Android\] Errors when app comes to foreground after long period of time in background

**URL:** https://qa.fmod.com/t/android-errors-when-app-comes-to-foreground-after-long-period-of-time-in-background/22821
**Category:** FMOD Engine
**Created:** [April 20, 2025, 1:00am UTC](https://qa.fmod.com/t/android-errors-when-app-comes-to-foreground-after-long-period-of-time-in-background/22821 "2025-04-20T01:00:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rhdr](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@rhdr](https://qa.fmod.com/u/rhdr)
#### Post date: [April 20, 2025, 1:00am UTC](https://qa.fmod.com/t/android-errors-when-app-comes-to-foreground-after-long-period-of-time-in-background/22821/1 "2025-04-20T01:00:21Z")

</div>

Using FMOD v2.03.07.

The app works fine with normal usage, even when sending the app to the background and back to the foreground many times, everything works.

The issue is that if the app is sent to the background, and accessed many hours later (approximately 7 hours), any previously playing audio tracks are no longer audible, and new audio does not play at all. The CPU usage also spikes, causing stuttering animations in the app, perhaps due to the following data spamming the logs continuously, until the app is shut down/restarted:

```auto
2025-04-20 10:41:02.708 31034-31091 yapp.myapp.demo com.myapp.demo D PlayerBase::~PlayerBase()
2025-04-20 10:41:02.708 31034-31091 AudioStreamTrack com.myapp.demo D open(), request notificationFrames = 0, frameCount = 0
2025-04-20 10:41:02.708 31034-31091 AudioTrack com.myapp.demo W createTrack_l(0): AUDIO_OUTPUT_FLAG_FAST denied by client, not shared buffer and transfer = TRANSFER_SYNC
2025-04-20 10:41:02.722 31034-31091 AudioStreamTrack com.myapp.demo D open() flags changed from 0x00000104 to 0x00000100
2025-04-20 10:41:02.722 31034-31091 AudioStreamTrack com.myapp.demo D open() perfMode changed from 12 to 10
2025-04-20 10:41:02.722 31034-31091 AAudioStream com.myapp.demo D setState(s#616) from 0 to 2
2025-04-20 10:41:02.726 31034-31091 AAudio com.myapp.demo I AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#616 ----------------
2025-04-20 10:41:02.737 31034-31091 AAudio com.myapp.demo D AAudioStream_close(s#616) called ---------------
2025-04-20 10:41:02.737 31034-31091 AAudioStream com.myapp.demo D setState(s#616) from 2 to 11
2025-04-20 10:41:02.738 31034-31091 AAudioStream com.myapp.demo D setState(s#616) from 11 to 12
2025-04-20 10:41:02.738 31034-31091 AAudioStream com.myapp.demo D ~AudioStream(s#616) mPlayerBase strongCount = 2
2025-04-20 10:41:02.738 31034-31091 AAudio com.myapp.demo D AAudioStream_close(s#616) returned 0 ---------
2025-04-20 10:41:02.751 31034-31091 fmod com.myapp.demo I FMOD::supportsLowLatency : Low latency = true, Pro Audio = true, Bluetooth On = false, Acceptable Block Size = true (96)
2025-04-20 10:41:02.752 31034-31091 fmod com.myapp.demo I FMOD::supportsSpatial : Supports Spatial = false, Spatial available = false, Spatial enabled = false
2025-04-20 10:41:02.752 31034-31091 AAudio com.myapp.demo I AAudioStreamBuilder_openStream() called ----------------------------------------
2025-04-20 10:41:02.753 31034-31091 AudioStreamBuilder com.myapp.demo I rate = 0, channels = 0, channelMask = 0, format = 0, sharing = SH, dir = OUTPUT
2025-04-20 10:41:02.753 31034-31091 AudioStreamBuilder com.myapp.demo I device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 0
2025-04-20 10:41:02.753 31034-31091 AudioStreamBuilder com.myapp.demo I usage = 14, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
2025-04-20 10:41:02.753 31034-31091 AudioStreamBuilder com.myapp.demo I privacy sensitive = false, opPackageName = (null), attributionTag = (null)
2025-04-20 10:41:02.753 31034-31091 yapp.myapp.demo com.myapp.demo D PlayerBase::PlayerBase()
2025-04-20 10:41:02.757 31034-31091 AudioStrea...nal_Client com.myapp.demo D configureDataInformation() original HW burst = 96, minMicros = 2000 => SW burst = 96
2025-04-20 10:41:02.757 31034-31091 IsochronousClockModel com.myapp.demo D setFramesPerBurst() - mFramesPerBurst = 96 - mBurstPeriodNanos = 2000000
2025-04-20 10:41:02.757 31034-31091 AAudioStream com.myapp.demo D setState(s#617) from 0 to 2
2025-04-20 10:41:02.757 31034-31091 AAudioFlowGraph com.myapp.demo I configure() source format = 0x00000005, channels = 2, sink format = 0x00000005, channels = 2, useMonoBlend = 0, audioBalance = 0.000000, isExclusive 0
2025-04-20 10:41:02.761 31034-31091 AAudio com.myapp.demo I AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#617 ----------------
2025-04-20 10:41:02.771 31034-31091 AAudio com.myapp.demo D AAudioStream_close(s#617) called ---------------
2025-04-20 10:41:02.771 31034-31091 AudioStrea...nal_Client com.myapp.demo D release_l(): mServiceStreamHandle = 0x000001C7
2025-04-20 10:41:02.771 31034-31091 AAudioStream com.myapp.demo D setState(s#617) from 2 to 11
2025-04-20 10:41:02.772 31034-31091 AAudioStream com.myapp.demo D setState(s#617) from 11 to 11
2025-04-20 10:41:02.772 31034-31091 AAudioStream com.myapp.demo D setState(s#617) from 11 to 12
2025-04-20 10:41:02.772 31034-31091 AudioStrea...nal_Client com.myapp.demo D ~AudioStreamInternal() 0xb40000711a3d92b0 called
2025-04-20 10:41:02.772 31034-31091 AAudioStream com.myapp.demo D ~AudioStream(s#617) mPlayerBase strongCount = 2
2025-04-20 10:41:02.772 31034-31091 AAudio com.myapp.demo D AAudioStream_close(s#617) returned 0 ---------
2025-04-20 10:41:02.783 31034-31091 AAudio com.myapp.demo I AAudioStreamBuilder_openStream() called ----------------------------------------
2025-04-20 10:41:02.783 31034-31091 AudioStreamBuilder com.myapp.demo I rate = 0, channels = 0, channelMask = 0, format = 0, sharing = SH, dir = OUTPUT
2025-04-20 10:41:02.783 31034-31091 AudioStreamBuilder com.myapp.demo I device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 0
2025-04-20 10:41:02.783 31034-31091 AudioStreamBuilder com.myapp.demo I usage = 14, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
2025-04-20 10:41:02.783 31034-31091 AudioStreamBuilder com.myapp.demo I privacy sensitive = false, opPackageName = (null), attributionTag = (null)
2025-04-20 10:41:02.784 31034-31091 yapp.myapp.demo com.myapp.demo D PlayerBase::PlayerBase()
2025-04-20 10:41:02.787 31034-31091 AudioStrea...nal_Client com.myapp.demo D configureDataInformation() original HW burst = 96, minMicros = 2000 => SW burst = 96
2025-04-20 10:41:02.787 31034-31091 IsochronousClockModel com.myapp.demo D setFramesPerBurst() - mFramesPerBurst = 96 - mBurstPeriodNanos = 2000000
2025-04-20 10:41:02.787 31034-31091 AAudioStream com.myapp.demo D setState(s#618) from 0 to 2
2025-04-20 10:41:02.787 31034-31091 AAudioFlowGraph com.myapp.demo I configure() source format = 0x00000005, channels = 2, sink format = 0x00000005, channels = 2, useMonoBlend = 0, audioBalance = 0.000000, isExclusive 0
2025-04-20 10:41:02.791 31034-31091 AAudio com.myapp.demo I AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#618 ----------------
2025-04-20 10:41:02.791 31034-31091 AAudio com.myapp.demo D AAudioStream_requestStart(s#618) called --------------
2025-04-20 10:41:02.791 31034-31091 AAudioStream com.myapp.demo D setState(s#618) from 2 to 3
2025-04-20 10:41:02.799 31034-31091 AAudio com.myapp.demo D AAudioStream_requestStart(s#618) returned 0 ---------
2025-04-20 10:41:02.801 31034-4988 AudioStrea...lay_Client com.myapp.demo D callbackLoop() entering >>>>>>>>>>>>>>>
2025-04-20 10:41:02.801 31034-4988 AudioStrea...nal_Client com.myapp.demo D onEventFromServer - got AAUDIO_SERVICE_EVENT_STARTED
2025-04-20 10:41:02.801 31034-4988 AAudioStream com.myapp.demo D setState(s#618) from 3 to 4
2025-04-20 10:41:03.799 31034-4988 AudioStrea...nal_Client com.myapp.demo W processData(): entered at 55476505578376 nanos, currently 55477503583059
2025-04-20 10:41:03.799 31034-4988 AudioStrea...nal_Client com.myapp.demo W processData(): TIMEOUT after 1000000000 nanos
2025-04-20 10:41:03.799 31034-4988 AudioStrea...nal_Client com.myapp.demo W processData(): wakeTime = 55477505779830, deadline = 55477505578376 nanos
2025-04-20 10:41:03.799 31034-4988 AudioStrea...nal_Client com.myapp.demo W processData(): past deadline by 201 micros
2025-04-20 10:41:03.799 31034-4988 IsochronousClockModel com.myapp.demo D mMarkerFramePosition = 0
2025-04-20 10:41:03.799 31034-4988 IsochronousClockModel com.myapp.demo D mMarkerNanoTime = 55476503317126
2025-04-20 10:41:03.799 31034-4988 IsochronousClockModel com.myapp.demo D mSampleRate = 48000
2025-04-20 10:41:03.799 31034-4988 IsochronousClockModel com.myapp.demo D mFramesPerBurst = 96
2025-04-20 10:41:03.799 31034-4988 IsochronousClockModel com.myapp.demo D mMaxMeasuredLatenessNanos = 0
2025-04-20 10:41:03.799 31034-4988 IsochronousClockModel com.myapp.demo D mState = 1
2025-04-20 10:41:03.799 31034-4988 AudioEndpoint com.myapp.demo D data readCounter = 0
2025-04-20 10:41:03.799 31034-4988 AudioEndpoint com.myapp.demo D data writeCounter = 0
2025-04-20 10:41:03.799 31034-4988 AudioStrea...lay_Client com.myapp.demo D callbackLoop() exiting, result = -885, isActive() = 1 <<<<<<<<<<<<<<
2025-04-20 10:41:03.811 31034-31091 AAudio com.myapp.demo D AAudioStream_requestStop(s#618) called
2025-04-20 10:41:03.812 31034-31091 AAudioStream com.myapp.demo D joinThread_l() pthread_join succeeded
2025-04-20 10:41:03.812 31034-31091 IsochronousClockModel com.myapp.demo D stop(nanos = 55477516527019) max lateness = 0 micros, DSP stalled 0 times
2025-04-20 10:41:03.812 31034-31091 AAudioStream com.myapp.demo D setState(s#618) from 4 to 9
2025-04-20 10:41:03.824 31034-31091 AAudio com.myapp.demo D AAudioStream_close(s#618) called ---------------
2025-04-20 10:41:03.824 31034-31091 AudioStrea...nal_Client com.myapp.demo D release_l(): mServiceStreamHandle = 0x000001C8
2025-04-20 10:41:03.825 31034-31091 AAudioStream com.myapp.demo D setState(s#618) from 9 to 11
2025-04-20 10:41:03.826 31034-31091 AAudioStream com.myapp.demo D setState(s#618) from 11 to 11
2025-04-20 10:41:03.826 31034-31091 AAudioStream com.myapp.demo D setState(s#618) from 11 to 12
2025-04-20 10:41:03.826 31034-31091 AudioStrea...nal_Client com.myapp.demo D ~AudioStreamInternal() 0xb40000711a3d92b0 called
2025-04-20 10:41:03.826 31034-31091 AAudioStream com.myapp.demo D ~AudioStream(s#618) mPlayerBase strongCount = 2
2025-04-20 10:41:03.826 31034-31091 AAudio com.myapp.demo D AAudioStream_close(s#618) returned 0 ---------
2025-04-20 10:41:03.838 31034-31091 AAudio com.myapp.demo I AAudioStreamBuilder_openStream() called ----------------------------------------

```

Has anyone come across this issue before? Is there anything that needs to be done to prevent this from happening?

---

<div class="post-metadata">

### Author: ![li\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/li_fmod/32/6577_2.png) [@li\_fmod](https://qa.fmod.com/u/li_fmod)
#### Post date: [April 24, 2025, 6:25am UTC](https://qa.fmod.com/t/android-errors-when-app-comes-to-foreground-after-long-period-of-time-in-background/22821/2 "2025-04-24T06:25:49Z")

</div>

Hi,

Thank you for sharing the version number and log output.

Unfortunately, I was not able to reproduce the issue on my end. Would it be possible to upload the project or a minmal repro to your [FMOD Profile](https://fmod.com/profile#uploads), so I can take a closer look?

---

<div class="post-metadata">

### Author: ![rhdr](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@rhdr](https://qa.fmod.com/u/rhdr)
#### Post date: [April 24, 2025, 6:38am UTC](https://qa.fmod.com/t/android-errors-when-app-comes-to-foreground-after-long-period-of-time-in-background/22821/3 "2025-04-24T06:38:15Z")

</div>

I won’t be able to upload the actual project, so I’ll create a minimal test project that, hopefully, reproduces the problem.

---

<div class="post-metadata">

### Author: ![rhdr](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@rhdr](https://qa.fmod.com/u/rhdr)
#### Post date: [April 28, 2025, 12:57pm UTC](https://qa.fmod.com/t/android-errors-when-app-comes-to-foreground-after-long-period-of-time-in-background/22821/4 "2025-04-28T12:57:50Z")

</div>

A project has been uploaded to my profile, filename “audiotest.zip”. I tried running this on an Android device for a few days, and could not replicate the problem, so I’m a little confused as to what could be causing the audio issue in the main project.

The audiotest project uses the [Axmol](https://github.com/axmolengine/axmol) game engine, which is a fork of the Cocos2d-x v4 game engine. If you wish to build the project, then instructions on setting it up are in the zip file. All relevant FMOD binaries are in there, and the project will work on Windows and Android. It may also build for iOS, but I haven’t tested that.
