Android How to update my messages list while activity is in background? -



Android How to update my messages list while activity is in background? -

i have simple chat application , i'm using gcm receive messages , update de ui, thing when app goes background ui not beingness updated, how can update ui while app in background?

this code:

private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string newmessage = intent.getextras().getstring(extra_message); string iduser = intent.getextras().getstring(extra_idquien); string fecha = intent.getextras().getstring(extra_fecha); string sound = intent.getextras().getstring(extra_audio); string video = intent.getextras().getstring(extra_video); string imagen = intent.getextras().getstring(extra_imagen); log.e("fecha", " "+fecha); if (iduser.equals(iduser)) { wakelocker.acquire(getapplicationcontext()); hashmap<string, string> map = new hashmap<string, string>(); map.put("mensaje", newmessage); map.put("fecmens", fecha); map.put("audio", audio); map.put("imagen", imagen); map.put("video", video); map.put("idusuario", iduser); arraylist.add(map); log.e("aƱadiendo el mensaje", newmessage); adapter.notifydatasetchanged(); wakelocker.release(); } } };

on first run of activity asynctask download messages timeline, while activity visible updated ui using broadcast receiver.

now need update ui while app goes background, whatsapp do.

appreciate help

is there reason can't these ui updates in onresume()? preferred method, since don't want app doing lots of ui work while it's not visible anyway.

you have private boolean needsuiupdate = false; in activity class. then, in onreceive() can set needsuiupdate = true;. , finally, in activity's onresume(), have this:

@override public void onresume() { if (needsuiupdate) { douiupdates(); } }

android android-listview broadcastreceiver google-cloud-messaging

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -