multithreading - Android UI thread update from web service -


if want update ui background thread when message received web service call, below considered safe option? i'm worried potential memory leaks having handler in application class

public class myapplication extends application {     private static long uithreadid;     private static handler uihandler;  @override public void oncreate() {     super.oncreate();     uithreadid = thread.currentthread().getid();     uihandler = new handler(); }  public static void customrunonuithread(runnable action) {     if (thread.currentthread().getid() != uithreadid) {         uihandler.post(action);     } else {         action.run();     } } } 

and in class deals messages received in separate threads:

 new thread(             new runnable() {                 @override                 public void run() {                         // make web service call                          myapplication.customrunonuithread(new runnable() {                             @override                             public void run() {                                 httpresponsehandler.onsuccess();                             }                         });                     }                 }             }).start(); 

my alternative use parallel asynctasks doing work in doinbackground method , updating ui in onpostexecute method. both of these options work, i'm not sure 1 'most' correct speak.

better way register broadcastreceiver , using localbroadcastmanager send broadcast on receiving message


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -