android - Publish progress from an external class during Async Task? -


i have async task doinbackground() method this:

       protected string doinbackground(string... params) {           myclass session = new myclass("email", "password");           return session.isauthorized();        } 

while myclass, in completly different package, this:

       private class myclass {                   // fields, constructors, etc                   public boolean isauthorized() {                              // stuff                              log("action 1...");                              // stuff                              log("action 2...");                              // other stuff                              return result;                   }                    public static void log(string str) {                              // here publish progress in async task                              // but, until now, it's kinda like:                              system.out.println(str);                   }        } 

the question is: how can pass log descriptions hold in log() method, external main activity "container", publishprogress() method? read thread: difficulty in changing message of progress dialog in async task - wasn't valid source of help, since method isn't contained in main class public class mainactivity extends activity {}.

edit #1 -

after work, realized way passing external class referece "main" thread, , implement there specific method publish progress. in such way:

       public void log(string str) {                   if (mthreadreference==null) {                              system.out.println(str);                   } else {                              mthreadreference.doprogress();                   }        } 

while mthreadreference points asynctask:

    private class myclasstask extends asynctask<string,string,string>  {         @override         protected string doinbackground(string... params) {             // constructs myclass instance reference , run main method             (new myclass("email", "password", this)).isauthorized();         }          public void doprogress(string str) {             publishprogress(str);         }          @override         protected void onprogressupdate(string... values) {             // stuff         }         @override         protected void onpostexecute(string result) {         }     } 

but, obviously, eclipse warning me: the method publishprogress() undefined type activity. how can write general , absolute method, in external class, can use in more 1 specific asyncthread?

                           --> logs in login thread 1                           /            external class ---> logs in login thread 2                           \                            --> logs in login thread 3 

i figured out way importing istance of asynctask, has public (not default option!), in main activity. trick, can invoke publishprogress method if it's protected.

    // myclass, in different package      import mainactivity.myclasstask mthreadreference = null;      // stuff...      public void log(string str) {             if (mthreadreference==null) {                     system.out.println(str);             } else {                     mthreadreference.doprogress("");             }     } 

while activity:

public class loginlanding extends activity {      // stuff...      public class myclasstask extends asynctask<string,string,string>  {             // bla bla bla, stuff...              public void doprogress(string str) {                     //             }     } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -