Android Challenge: skipped frames... shutdown VM... NULLPointerException.. on return of Intent data to onActivityResult -


i've got bit of challenge... here following high level:

from user perspective:

they activity (stockcountlistactivity) shows them list of open stock counts - choose 1 , go activity (stockcountactivity) shows them items can update qtys on.

behind scenes:

the data both activities comes web service... i've written following class helper:

public class webservicetask extends asynctask<string, integer, string> 

with customary async methods... magic no problem... , in end calls

@override protected void onpostexecute(string result) {      resultstring = result;     _listener.handleresponse(tasknumber,scode,result);     pdlg.dismiss();  } 

where _listener interface i've written hook go calling class (either activity)... per following:

public interface webtasklistener {     public void handleresponse(int tasknum, int scode, string result); } private webtasklistener _listener; 

all of works great far... comes challenge... in handleresponse of child activity (stockcountactivity) have following:

@override public void handleresponse(int tasknum, int scode, string result) {     if (result == null)         return;     if (tasknum == putcountitems_task)     {         intent returnintent = new intent();         returnintent.putextra("selgroup",-1);         returnintent.putextra("selchild",-1);         setresult(result_ok,returnintent);              this.finish();     }  } 

through debugging can verify returnintent correct here , extras have been added correctly -1 values... intention(no pun intended) here trickle stockcountlistactivity (the first user dialog) , pass these values. happens quite different...

first... background... called stockcountactivity (second dialog) following code stockcountlistactivity (first dialog):

    intent startnewactivityopen = new intent(this, stockcountactivity.class);     startnewactivityopen.setflags(intent.flag_activity_clear_top);     int newcountid = addnewcount(n);     startnewactivityopen.putextra("categoryid", n);     startnewactivityopen.putextra("loadtype", "new");     startnewactivityopen.putextra("countid", newcountid);     startnewactivityopen.putextra("selgroup", -1);     startnewactivityopen.putextra("selchild", -1);     startactivityforresult(startnewactivityopen, 1); 

finally... after long winded explanation... problem on onactivityresult in stockcountlistactivity.

    protected void onactivityresult(int requestcode, int resultcode, intent data) {          if (requestcode == 1 && data != null) {              if (resultcode == result_ok) {                 bundle extras = getintent().getextras();                 if (extras != null) {                     currentcount.selgroup = extras.getint("selgroup", -1);                     currentcount.selchild = extras.getint("selchild", -1);                 } 

the data has no extras , empty though i've verified fine leaving stockcountactivity. logcat shows following.

    05-02 09:39:59.664: i/choreographer(16548): skipped 3206 frames!  application may doing work on main thread.     05-02 09:44:30.304: d/androidruntime(16548): shutting down vm     05-02 09:44:30.304: w/dalvikvm(16548): threadid=1: thread exiting uncaught exception (group=0x40c15930)     05-02 09:44:30.374: e/androidruntime(16548): fatal exception: main     05-02 09:44:30.374: e/androidruntime(16548): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=intent { flg=0x4000000 cmp=com.oat/.stockcount.stockcountactivity (has extras) }} activity {com.oat/com.oat.stockcount.stockcountlistactivity}: java.lang.nullpointerexception     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activitythread.deliverresults(activitythread.java:3319)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activitythread.handlesendresult(activitythread.java:3362)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activitythread.access$1100(activitythread.java:141)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activitythread$h.handlemessage(activitythread.java:1282)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.os.handler.dispatchmessage(handler.java:99)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.os.looper.loop(looper.java:137)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activitythread.main(activitythread.java:5041)     05-02 09:44:30.374: e/androidruntime(16548):    @ java.lang.reflect.method.invokenative(native method)     05-02 09:44:30.374: e/androidruntime(16548):    @ java.lang.reflect.method.invoke(method.java:511)     05-02 09:44:30.374: e/androidruntime(16548):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793)     05-02 09:44:30.374: e/androidruntime(16548):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560)     05-02 09:44:30.374: e/androidruntime(16548):    @ dalvik.system.nativestart.main(native method)     05-02 09:44:30.374: e/androidruntime(16548): caused by: java.lang.nullpointerexception     05-02 09:44:30.374: e/androidruntime(16548):    @ com.oat.stockcount.stockcountlistactivity.onactivityresult(stockcountlistactivity.java:323)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activity.dispatchactivityresult(activity.java:5293)     05-02 09:44:30.374: e/androidruntime(16548):    @ android.app.activitythread.deliverresults(activitythread.java:3315)     05-02 09:44:30.374: e/androidruntime(16548):    ... 11 more 

to summarize, sequence of events follows.
1) webservicetask (an asynctask) completes work , then
2) calling stockcountactivity's handleresponse method
3) in turn creating returnintent , finishing activity
4) going stockcountlistactivity's onactivityresult method

i believe real problem message telling me there happening on main thread , shutting down vm. once happens, can understand why intent data gets lost. have no idea why complaining doing work on main thread.

i'm sure doing stupid. appreciated.
thanks

ok... after many many hours of debugging , research... came across great answer @ following:

android return activity extras returns null

it seems though real issue here @ following line:

                bundle extras = getintent().getextras(); 

it should be:

            bundle extras = data.getextras(); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -