android - AsyncTask calling main class method, did it work fully in background? -


this problem..i calling method in doinbackground of asynctask class, method declared in main activity class. work in background thread? or need write whole method inside doinbackground ??

protected string doinbackground(string... params) {     getallusersfromserver();                  return null; } 

this getallusersfromserver(); declared in main class. method download data server using rest..

i need run whole process in background thread. works?

does work in background thread?

afaik, yes works in background thread.

do need write whole method inside doinbackground ??

no need that.

onpostexecute works next moment.. users information still loading

this main point, working line line, when goes execute getallusersfromserver(); control goes execute method gets executed in background thread. [to understand add 1 log print line below method call in doinbackground , 1 in method's loop , see if loop doesn't complete doinbg log printed]

this happens because, method getallusersfromserver(); void, , android takes other independent work done , doesn't wait till gets complete , keep moving next lines.

solution :

just add 1 return type i.e. boolean getallusersfromserver(); , add return statement in method return true; , in doinbackground boolean flg = getallusersfromserver();


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 -