سؤال

I was going through whatsapp application and I noticed that, for the first time it fetches thumbnails from the server, keeps them in cache memory, and thereafter it fetches these from the cache memory instead of server. (Like bitmap lazyloading).

Till now I have completed implementing the bitmap lazyloading part.

However I have a question as follows:

When any contact changes its profile picture how does the user's whatsapp application detects that particular change and how does it update that particular thumbnail only, cause the application is supposed to fetch the thumbnails from cache memory.

I am clueless about this. Any help is appreciated.

EDIT:

Does it use push notification to notify the client applications to update the corresponding profile thumbnail?

هل كانت مفيدة؟

المحلول

Source: WhatsApp is build upon C2DM and XMMP for message delivery. MQTT is another protocol which is used to minimise the battery usage.

When any contact changes its profile picture how does the user's whatsapp application detects that particular change and how does it update that particular thumbnail only, cause the application is supposed to fetch the thumbnails from cache memory

Answering your question: So WhatsApp may be using XMMP push or a GCM push notification(C2DM is deprecated ;] ) to inform all the client that some event has occurred and all it's client needs to take care of the same. In your case event is to update your profile pic in devices of your friends in WhatsApp contacts

In your case, you can use GCM to update clients regarding such events. I don't have much idea about XMPP but You can also have a look at Smack API(An Open Source XMPP (Jabber) client library for instant messaging and presence) and this interesting post

I hope I answered your question. Good Luck :)

Edit:

GCM is a service from Google that uses a persistent XMPP connection to communicate with Android devices. You can use any of the following techniques of GCM to achieve this.

نصائح أخرى

An easy way to handle this situation will be to keep an modified datetime in the table where you store the path of the image and thumbnail. You have to keep the url of the image along with the modified date as the parameter.

Eg:

http://yourdomain.com/images/user_id.png?q=modifieddatetime

Whenever the app will try to open this link, it will first check whether it is available in cache or not. If not the new image will be fetched from the server.

I have not tried this on Android, but it should work. I usually do this in my web applications.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top