这里是一个第三方的监听,当你用完后要销毁,销毁的步骤如下
RongIMClient.addOnReceiveMessageListener(new OnReceiveMessageWrapperListener() {
@Override
public void onReceivedMessage(Message message, ReceivedProfile profile) {
runOnUiThread(() -> {
mChatConversationAdapter.addFirst(message);
MessageContent messageContent = message.getContent();
if (messageContent instanceof GiftMessage) {
GiftMessage giftMessage = (GiftMessage) messageContent;
onPlayerGiftAimi(giftMessage);
onPlayerGiftAimi(((GiftMessage) messageContent));
onPlayerGiftAimi(((GiftMessage) message.getContent()));
}
});
}
});
1.先将那个对象做成全局 就是将下面的代码框选,然后点击Ctrl+ALt+F 就可以做成全局了
new OnReceiveMessageWrapperListener() {
@Override
public void onReceivedMessage(Message message, ReceivedProfile profile) {
runOnUiThread(() -> {
mChatConversationAdapter.addFirst(message);
MessageContent messageContent = message.getContent();
if (messageContent instanceof GiftMessage) {
GiftMessage giftMessage = (GiftMessage) messageContent;
onPlayerGiftAimi(giftMessage);
onPlayerGiftAimi(((GiftMessage) messageContent));
onPlayerGiftAimi(((GiftMessage) message.getContent()));
}
});
}
}
2.就会自动出现下面这句了,mAddOnReceiveMessageListener就是全局的了
RongIMClient.addOnReceiveMessageListener(mAddOnReceiveMessageListener);
3.当生命周期到了销毁的时候将那个全局一起销毁了mAddOnReceiveMessageListener
@Override
protected void onDestroy() {
RongIMClient.removeOnReceiveMessageListener(mAddOnReceiveMessageListener);
super.onDestroy();
}
还有一种更高级一点的,就是在BaseActivity里面添加
|