azure - How to Call a Another Activity AsyncTask Class from a Android Activity Getting NPE -


  1. abc.class first activity class.
  2. xyz.class asynctask activity class.

having more 10 async task in application ,so kept async task in separate class.

i calling activity asynctask class(xyz.class) activity(abc.class).

problem:

1.i can call async task abc.class but, kept instance values inside oncreate of xyz.class class(getting azure local database data) . asynctask getting npe.

2.oncreate method not running, when async task calling other activity.

3.inside doinbackgroud iam getting npe error.

help me how solve ,else suggest me other solution.

edit:1

in async task iam fetching data azure server local db,so need instances kept inside oncreate.

abc.class

calling async task

 asynctaskload_usergroupmappingtableclass myclass = new asynctaskload_usergroupmappingtableclass(getapplicationcontext());                                                 myclass.execute(); 

xyz.class

th_tbusergroupmapping database name

 /*client table5 */     private static mobileserviceclient mclient_usergroupmapping;      //online client  azure     public  static mobileservicetable<th_tbusergroupmapping> mtodotable_usergroupmapping_serverazure;      //offline client  local datbase.      public static mobileservicesynctable<th_tbusergroupmapping> mtodotable_usergroupmapping_local_database;        @override         protected void oncreate(bundle savedinstancestate)         {             super.oncreate(savedinstancestate);             try {                 // create mobile service client instance, using provided                  // mobile service url , key                 mclient_usergroupmapping = new mobileserviceclient(                         "***********",                         "**************",                         this).withfilter(new progressfilter());       /*usergroupmapping*/                 // mobile service table instance use                 mtodotable_usergroupmapping_serverazure = mclient_usergroupmapping.gettable(th_tbusergroupmapping.class);                  // local database table instance use                 mtodotable_usergroupmapping_local_database= mclient_usergroupmapping.getsynctable("th_tbusergroupmapping", th_tbusergroupmapping.class);                   //init local storage                 initlocalstore().get();               }             catch (malformedurlexception e)             {                  log.i("oncreate", "there error creating mobile service. verify url......!");              } catch (exception e) {                  log.i("oncreate", "exception occur......!");             }          }        public static class asynctaskload_usergroupmappingtableclass extends asynctask<void, string, void>         {              private context context;             public asynctaskload_usergroupmappingtableclass(context context) {                 this.context = context;             }              @override             protected void onpreexecute()             {                 super.onpreexecute();              }             @override             protected void doinbackground(void... params)             {             }      @override             protected void onpostexecute(void result)             {                  try                 {                      log.i("done ", "data sync done usergroupmapping 1");                   } catch (exception e)                 {                     e.printstacktrace();                      log.i("exception ", "post excecute");                 }             }          } 

do not keep asynctask in activity then; keep in ordinary java class , not try keep data inside instances of class; store information elsewhere: in singleton class, or in sharedpreferences, or sqlite database, etc.


Comments