android - Trigger event when AsyncTask is complete using Listener -


i'm having confusion on how use listeners pass information between classes , activities.

the scenario this:
have task reads data sqlite database , puts data arraylist passed adapter displays on screen.

the question:
app crashes when attempt update listener interface value. doesnt show in logcat...it hangs app. kindly point out i'm going wrong. - thanks

details:
have database processing done class called datbaseroutines , within inner method doing heavy lifting. method using asynctask not hog main thread.

i have created , interface single method

 public interface databaseprocesslistener {   public void processingisdone(boolean blnprocessisfinished); }  

in databaseroutines class creating private variable

private databaseprocesslistener dbprocesslistener; 

along setter

   public void setdbprocesslistener(databaseprocesslistener dbprocesslistener) {     this.dbprocesslistener = dbprocesslistener;     } 

when processing done, use postexecute method update listener can change value in listener true (ie db processing done) below code

            protected void onpostexecute(boolean aboolean) {                 super.onpostexecute(aboolean);                 dialog.dismiss(); //i have progress dialog during processing ,                                         //closed here                  if (blnupdatesucceededstatus)                   {                      dbprocesslistener.processingisdone(true);                   }                     else                    {                     toast.maketext(ctx, "transactions processing                         failed",toast.length_short);                    } ; 

finally in activity displaying data gathered database implement listener. see below.

public class myactivity extends activity implements databaseprocesslistener  {  @override public void processingisdone(boolean blnprocessisfinished) {     if(blnprocessisfinished){         populateexpandablelistview();     }    public void populateexpandablelistview() {    //code populating listview goes here;      } } 

after digging found logcat error..its nullpointer exception

05-05 11:11:18.590: error/androidruntime(22339): fatal exception: main     java.lang.nullpointerexception     @ com.example.mledger.databaseroutines$1.onpostexecute(databaseroutines.java:258)     @ com.example.mledger.databaseroutines$1.onpostexecute(databaseroutines.java:141)     @ android.os.asynctask.finish(asynctask.java:631)     @ android.os.asynctask.access$600(asynctask.java:177)     @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644)     @ android.os.handler.dispatchmessage(handler.java:99)     @ android.os.looper.loop(looper.java:137)     @ android.app.activitythread.main(activitythread.java:4921)     @ java.lang.reflect.method.invokenative(native method)     @ java.lang.reflect.method.invoke(method.java:511)     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038)     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805)     @ dalvik.system.nativestart.main(native method) 

unfortunately app hanging , interface never updates activity displays data true (ie processing done)

do point me in right direction. - thanks

sounds dbprocesslistener variable null. call setter , pass initialized listener object time before invoke dbprocesslistener.processingisdone(true);?


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -