Android Getintent().Getextras() Returns Null

getIntent().getExtras() returns null Android

Thanks to everyone, all the answers moved me closer to making it work but I needed to change the PendingIntent to the following to nail it.

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Thanks...<3

(Activity(context)).getIntent().getExtras() return null

Try stepping through this under the debugger:

public class Request {
private Context context;
...
public Request(Context context) {
this.context = context;
try {
Intent intent = context.getIntent();
Bundle extras = intent.getExtras(); // <-- I'll betcha' this is returning "null"
this.arguments = new Arguments(extras);
...
} catch (Exception e) {
Log.i("output", "no arguments has been found " + e.toString());
}
...

Why Activity getIntent().getExtras() will return null sometimes?

This could be a buggy ACTION_SEND implementation that failed to attach any extras. This could be some automated script — or script kiddie — manually invoking your activity without any extras.

Since the activity is exported, I recommend some "defensive programming". Do not assume the existence of an extras Bundle. Instead, "gracefully degrade" as best you can in that case.

null value in getIntent.getExtras.getString()

Intent i = new Intent(yourcurrentactivity.this, OtherScreen.class);

i.putExtra("id1", "first");
i.putExtra("id2", "second");
startActivity(i);

Bundle extras = getIntent().getExtras();
if (extras != null) {
String result = extras.getString("id1");
System.out.println("yeah"+result);
}

Bundle = getIntent().getExtras() is always null

You're using getIntent() instead of the Intent data... So, that's not the intent that you have passed via startActivityForResult

For example

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == REQUEST) {
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
String previousActivity = extras.getString("FROM_ACTIVITY");

Also, if getIntent().getExtras() works outside of the click event, then make it a field.

private Bundle extras;

public void onCreate(Bundle savedInstanceState) {
....
this.extras = getIntent().getExtras();
}

And use those in the onClick

Ideally, though, I'd suggest not defining the entire adapter within the Activity code and instead create a separate class file. In which case, you cannot use the Activity Intent within the adapter code



Related Topics



Leave a reply



Submit