1

I have an unexpected crash on my app in production. I have an activity that I always start using a newInstance method that add some extras to the intent :

public static Intent newInstance(final Context context, @NonNull final Location location) {
        final Intent intent = new Intent(context, LocationActivity.class);

        final Bundle extras = new Bundle();
        extras.putParcelable(BUNDLE_ITEM_LOCATION, Location);
        intent.putExtras(extras);

        return intent;
    }

And here is my onCreate method :

@Override
@CallSuper
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Bundle extras = getIntent().getExtras();
    if (extras == null || !extras.containsKey(BUNDLE_ITEM_LOCATION)) {
        throw new IllegalArgumentException(LocationActivity.class.getName()
                + " must be created by using newInstance()");
    }

                 [... Some other code ...]
}

And this IllegalArgumentException is thrown in production. It's super weird because this case should never happen. Any idea about the cause?

Thanks in advance.

Denis Pinna
  • 151
  • 1
  • 11

1 Answers1

1

Try this:

public static Intent newInstance(final Context context, @NonNull final Location location {
        final Intent intent = new Intent(context, LocationActivity.class);
        intent.putExtras(BUNDLE_ITEM_LOCATION, Location);
        return intent;
    }