Solving FCM Notification Issues in Xiaomi Devices with MIUI
in Post with 0 comment

## A Persistent Problem: FCM Notifications Disappearing on Xiaomi Devices

FCM (Firebase Cloud Messaging) is a powerful tool for delivering timely notifications to Android users. However, on Xiaomi devices running MIUI, a common issue arises where apps appear to be running but fail to receive notifications after a period of inactivity in the background. This issue, likely caused by MIUI's background app management optimizations, can be frustrating for users and developers alike.

**The Symptom:**
You may notice your app, even when apparently "running" in the background (according to the notification tray), doesn't receive notifications. Even though FCM Diagnostics confirms the notification is delivered, you'll see a `No response to broadcast from xxxx` message. This suggests your app, although in a seemingly "running" state, is effectively 'tombstoned' by MIUI's power management. Ending and relaunching the app resolves the issue temporarily.

**Potential Root Cause:**
MIUI's aggressive battery optimization features, particularly its unique 'tombstone mechanism,' can contribute to this problem. The mechanism, designed to conserve battery, puts apps to sleep after a period of inactivity. In some cases, apps marked as 'running' may actually be tombstoned, preventing them from receiving notifications.

**Workarounds:**
- **Disable Smart Battery Restrictions:** Users often find temporarily disabling the intelligent battery limits in their device settings allows FCM notifications to work as expected. This circumvents MIUI's restrictions but comes at the cost of increased battery drain.
- **MIUIGMS Alternative (Less Ideal):** MIUIGMS, a component within MIUI, allows developers to bypass background restrictions and keep apps continuously active. While effective, this approach results in high battery consumption, making it less than ideal.

**An Ideal Solution:**
A more nuanced solution would involve modifying fcmfix so it not only wakes but also 'revives' the app from a tombstoned state. Simulating a foreground interaction with the app could be a starting point to achieve consistent notification reception.

The article has been posted for too long and comments have been automatically closed.