android - When onActivityResult is ran resultCode is 0 and data is null -


i have activity sends boolean array inventory class maingame activity. when onacivityresult runs resultcode 0 , data null.

starting inventory activity:

@requiresapi(api = build.version_codes.jelly_bean)     public void openinventory(view v) {         intent bag = new intent(maingame.this, inventory.class);         bag.putextra(booinventory, inventory);         startactivityforresult(bag, requestitem);     } 

ending inventory activity:

public void onpause(){         intent item = new intent(inventory.this, maingame.class);//data sent maingame activity         item.putextra(tools, itemused);         setresult(result_ok, item);         super.onpause();     } 

onactivityresult: (toaster method creates toast)

@override     public void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);          if(requestcode == 2){             if(resultcode == result_ok){                 toaster("result ok", 500);             }              if(data != null){                 toaster("it worked", 1500);             }else{                 toaster("fail!", 1500);             } } 

firstly, shouldn't in onpause().

secondly, replace

intent item = new intent(inventory.this, maingame.class)  

with this:

intent returnintent = new intent(); 

bonus: use static variables code such as:

private static int second_activity_request_code = 2; 

and use variable inside methods instead.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -