Mobile Development 28 min read

Why Android Activity onStop/onDestroy Is Delayed by 10 Seconds When an Infinite Animation Is Running

The article explains that an infinite View animation continuously posts invalidate messages to the MessageQueue, preventing the idle handler from running and causing the Activity's onStop and onDestroy callbacks, scheduled with a 10‑second idle timeout, to be delayed until the queue becomes idle.

Top Architect
Top Architect
Top Architect
Why Android Activity onStop/onDestroy Is Delayed by 10 Seconds When an Infinite Animation Is Running

This article investigates a bug where an Android Activity's onStop and onDestroy methods are delayed by about 10 seconds after the Activity finishes. The root cause is an infinite RotateAnimation started on the previous page, which repeatedly invalidates the view hierarchy.

The animation's getTransformation method always returns true (the more flag) because the repeat count is INFINITE . Consequently, applyLegacyAnimation always calls parent.invalidate(...) , which posts new messages to the MessageQueue on every frame.

When the current Activity calls finish() , the system schedules an idle timeout message ( IDLE_TIMEOUT_MSG ) to trigger activityIdleInternalLocked after 10 seconds, which would normally invoke finishCurrentActivityLocked and destroy the Activity. However, the message queue never becomes empty because the animation continuously adds new messages, so the idle handler ( MessageQueue.IdleHandler ) never runs.

The article outlines the full call chain from ActivityThread through TransactionExecutor , MessageQueue.next() , and the idle handler execution, showing how the perpetual animation blocks the idle processing.

Three practical solutions are proposed: pause the animation in onPause , replace the legacy animation with a ValueAnimator , or release resources early in onPause when the Activity is finishing.

PerformanceanimationAndroidMessageQueueIdleHandlerActivityLifecycle
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.