How to implement the IM function in the app four create a robust message sending module-arrow Buckle technology Arrownock

Source: Internet
Author: User

How to implement the IM feature in the app four create a robust message sending module

Anim Chat is a heartbeat to keep the device and the server connection between the online, and sometimes because of network or other reasons cause the connection is interrupted, the user logged on the device on the server side will automatically offline. Then when the message is sent, the server returns the exception that the user has gone offline, causing the message to fail to send successfully.

In order to avoid this problem, we can use some techniques in the code to solve it.

1. Setting variables

Set a global variable isfromsendmsg to false. Private Boolean isfromsendmsg = false;

2. Determine if the user is online

When clicking the Send Message button on the interface, first determine if the user is online. If online, the message is sent directly. If you are not on the line, log in and send the message first.


    //If the user is offline, log in again and send the message     if  (Anim.getcurrentstatus ()  ==  animstatus.offline)  {        refreshuiview (); //  First refresh the interface         //login          Anim.connect (clientId);         //sets the global variable to true, which means to send a message immediately after logging in, without going to the other process         isFromSendMsg = true;         } else {             Anim.sendmessage (clientids,msg);        }      } 



3. Login Judgment

Log in by the global variables to determine whether this login needs to send a message immediately. If so, change the global variables back before sending the message.


@Override public void Statusupdate (final animstatusupdatecallbackdata data) {if (isfromsendmsg && data).        GetStatus () = = Animstatus.online) {isfromsendmsg = false;        Anim.sendmessage (Clientids, msg); } else {//normal login process}}



4. Techniques for Interface Processing

Click the Send Message button, immediately put the data into the database, refresh the interface, with loading animation to express. When the message is successfully sent, the data is modified once, the interface is refreshed, and the loading animation is removed.


How to implement the IM feature series in the app article:

A common analysis of offline messages

The second fast realization of the offline message module

Three fast implementation of offline message push module

The four create a robust message sending module

The five rapid implementation of picture receiving and sending

The six fast realization of group chat advanced features

Seven fast implementation of chat list sorting module



This article from "Arrow Buckle technology Arrownock" blog, reproduced please contact the author!

How to implement the IM function in the app four create a robust message sending module-arrow Buckle technology Arrownock

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.