Sometimes, we keep sending a notification. If the number of notifications reaches a fixed limit, the notification bar may disappear (Android system lower than 3.0). This problem is actually a bug in Android, next I will analyze the cause of this problem.
I. Reasons
When this problem occurs, we analyze the log and learn that,Com. Android. systemuiThe ANR is in progress because it times out when processing broadcast messages, and this ANR will causeCom. Android. systemuiThe process is dead. Generally, the status bar maintains the notification information and the remote views of all notifications. If a client program continuously sends notifications, the system uses the memory to create these remote views without interruption. Therefore, the garbage collector (GC) starts to recycle the memory, and the UI starts to slow down (in other words, changing the card ), if the client program keeps sending notifications at this time, the UI will become slower and slower. Finally, the ANR error occurs. We can write a demo to reproduce this problem. Start a timer and send notifications continuously. The status bar may disappear. The log is as follows:
D/dalvikvm(11985): GC_EXPLICIT freed 1258 objects / 84016 bytes in 1157msD/dalvikvm( 85): GC_FOR_MALLOC freed 52216 objects / 1900968 bytes in 130msD/dalvikvm( 85): GC_FOR_MALLOC freed 49465 objects / 1805248 bytes in 125msD/dalvikvm( 85): GC_FOR_MALLOC freed 53106 objects / 1909992 bytes in 134ms...12-10 15:07:11.088 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.098 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.098 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.098 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.108 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.128 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.128 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.138 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!12-10 15:07:11.158 E/JavaBinder( 2240): !!! FAILED BINDER TRANSACTION !!!
From this log, we can see that GC continuously releases the memory, which causes the UI response delay. This phenomenon can be reproduced on Android 2.1, 2.2, and 2.3. I have not tried more than 3.0. I don't know if the same problem exists. When the remoteview in the notification bar increases to a certain number, that is, it exceeds ibinder. the RemoteException will throw the range that transcat () can handle. Sometimes, if the VM restriction is exceeded, the app may be suspended.
2. Solutions
The reason for this problem is that we know how to solve it. Instead of sending notifications each time, we can use the same message ID to update the notifications, rather than recreate them.
3. Other links
This question has actually been raised on the Google Forum. For details, refer:
Http://code.google.com/p/android/issues/detail? Id = 13941
Http://code.google.com/p/csipsimple/issues/detail? Id = 676