Skip to content

Commit caafcd6

Browse files
authored
Merge pull request Blankj#1485 from xiexindev/master
Fix: MessengerUtils java.lang.IllegalStateException
2 parents 293fa10 + ab073b7 commit caafcd6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/utilcode/src/main/java/com/blankj/utilcode/util/MessengerUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,17 @@ public int onStartCommand(Intent intent, int flags, int startId) {
317317
}
318318

319319
private void sendMsg2Client(final Message msg) {
320+
final Message obtain = Message.obtain(msg); //Copy the original
320321
for (Messenger client : mClientMap.values()) {
321322
try {
322323
if (client != null) {
323-
client.send(msg);
324+
client.send(Message.obtain(obtain));
324325
}
325326
} catch (RemoteException e) {
326327
e.printStackTrace();
327328
}
328329
}
330+
obtain.recycle(); //Recycled copy
329331
}
330332

331333
private void consumeServerProcessCallback(final Message msg) {

0 commit comments

Comments
 (0)