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
Converting Utf-8 to Iso-8859-1 in Java - How to Keep It as Single Byte
How to Create My Own Appender in Log4J
Android - Save Image from Url Onto Sd Card
Google Sign in Signed APK Not Working
What Does Transitive = True in Gradle Exactly Do (W.R.T. Crashlytics)
Android Intent for Sending Email with Attachment
Why Menuitemcompat.Getactionprovider Returns Null
How to Update Xml File from Another Xml File Dynamically
Multiple Typeface in Single Textview
Use Startactivityforresult from Non-Activity
Could Not Find Method in Parent or Ancestor Context
Why Does My Compare Method Throw Exception -- Comparison Method Violates Its General Contract!
Libjvm.So: Cannot Open Shared Object File: No Such File or Directory
Sending Variable from One Jsp to Another Jsp