You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Nullpointer with default intent.getExtra methods #1898
See code below i have an activity which has a setResult with a byte[] as argument. However when i press the back button on said activity it crashes in the generated class because the intent is null. See code below for the error:
this is the currently generated code: Bundle extras_ = (((data!= null)&&(data.getExtras()!= null))?data.getExtras():new Bundle()); byte[] bitmap = data.getByteArrayExtra(BITMAPRESULTKEY_EXTRA);
Activity
WonderCsabo commentedon Nov 16, 2016
Can you post the annotated code?
rickbijkerk commentedon Nov 16, 2016
this is the code that should receive the result:
@OnActivityResult(REQUEST_PICTURE) void onPictureTaken(int resultCode, @OnActivityResult.Extra(value = TakePictureActivity.BITMAP_RESULT_KEY) final byte[] bitmap)and this is where i sent it
Intent intent = new Intent(); intent.putExtra(BITMAP_RESULT_KEY, PhotoService.convertPhotoToJPEG(photo)); setResult(RESULT_OK, intent); finish();rickbijkerk commentedon Nov 16, 2016
this is the currently generated code:
Bundle extras_ = (((data!= null)&&(data.getExtras()!= null))?data.getExtras():new Bundle()); byte[] bitmap = data.getByteArrayExtra(BITMAPRESULTKEY_EXTRA);while i think it should be
Bundle extras_ = (((data!= null)&&(data.getExtras()!= null))?data.getExtras():new Bundle()); byte[] bitmap = (byte[]) extras_.get(BITMAPRESULTKEY_EXTRA);as the extras_ variable bundle is currently unused. Note the cast in the above statement
Zulqurnain commentedon Nov 19, 2016
i'm facing similar issue , @OnActivityResult annotated method never get's called
Zulqurnain commentedon Nov 20, 2016
Well i fixed that , by passing 'this' instead of 'context' in Activity_.initent(this).start();
WonderCsabo commentedon Nov 23, 2016
@rickbijkerk hmm, we should indeed use the
extras_variable. @dodgex wdyt?dodgex commentedon Nov 23, 2016
@WonderCsabo I think this is a good idea
WonderCsabo commentedon Nov 23, 2016
Can you contribute?
dodgex commentedon Nov 23, 2016
I'll see what I can do the next days.
dodgex commentedon Nov 24, 2016
I just opened a PR to correct this.
WonderCsabo commentedon Nov 24, 2016
Fixed, thanks to @dodgex !
rickbijkerk commentedon Dec 2, 2016
looking good thanks!