4

I am using bug-sense for bug reporting. After the latest update to my app, I have been getting null pointers on.

This problem happens only for Android 4.1.1. There are 25 occurrences of these null pointers in almost every activity, and from Android 4.1.1 exclusively.

Anyone know why this is happening?

Intent i= new Intent(context, MyActivity.class);
i.putExtra("id", id);
context.startActivity(i);

getting extras:

Bundle extras = getIntent().getExtras();
String id = extras.getString("id"); //null pointer
Grodriguez
  • 21,501
  • 10
  • 63
  • 107
124697
  • 22,097
  • 68
  • 188
  • 315

2 Answers2

0

Looks very similar to this even if not related to Android 4.1.1

Android getIntent().getExtras() returns null

Are you using tabs? I think you need to give a little bit more context, code to have a valid answer.

Community
  • 1
  • 1
Nico
  • 101
  • 1
  • 2
  • 4
0

I faced same problem in activity with singleTask launch mode on android 4.1 only. It reproduced if I start this activity when its instance had been already started before.

It seems that getIntent() returns first intent insted of current. Android docs says:

getIntent(): Return the intent that started this activity.

I found out that in onCreate I get first intent (activity launcher), but in onNewIntent I get proper intent with extras. So I've overrided onNewIntent like this:

@Override
public void onNewIntent(Intent intent) {
  super.onNewIntent(intent);
  setIntent(intent);
}

to get proper intent returned by getIntent in onCreate.

Some discussion about this overriding you can find here:
Is there any reason not to call setIntent when overriding onNewIntent?

Kirill
  • 7,580
  • 6
  • 44
  • 95