Gavin Wright
Gavin Wright

Reputation: 3212

Intent extras are not being delivered on a specific device

In Activity A I essentially have:

Long customerId = 123;
intent.putExtra("customerId", customerId);
startActivity(intent);

And in Activity B's onCreate() I have:

mCustomerId = getIntent().getLongExtra("customerId", -1);

But for one of my users (Nexus 4, Android 6.0.1), mCustomerId resolves to -1 in Activity B (-1 being the default value). This code works fine for my other 1000 users.

This same user has a similar issue receiving an intent extra in a library I use:

https://github.com/Ereza/CustomActivityOnCrash/issues/56

How can this happen?

Log:

Fatal Exception: java.lang.IllegalArgumentException
Update is not supported for content://appinventor.ai_GavinGT.TipTracker_9_1_426am_ready_for_market/customers/-1
appinventor.ai_GavinGT.DeliveryTipTrackerPro_ready_for_market.data.TipProvider.update (TipProvider.java:326)
android.content.ContentProvider$Transport.update (ContentProvider.java:355)
android.content.ContentResolver.update (ContentResolver.java:1364)
appinventor.ai_GavinGT.DeliveryTipTrackerPro_ready_for_market.customer_info.CustomerProfileActivity.saveChanges (CustomerProfileActivity.java:208)
appinventor.ai_GavinGT.DeliveryTipTrackerPro_ready_for_market.customer_info.CustomerProfileActivity.access$400 (CustomerProfileActivity.java:58)
appinventor.ai_GavinGT.DeliveryTipTrackerPro_ready_for_market.customer_info.CustomerProfileActivity$6.onDebouncedClick (CustomerProfileActivity.java:137)
appinventor.ai_GavinGT.DeliveryTipTrackerPro_ready_for_market.custom_classes.DebouncedOnClickListener.onClick (DebouncedOnClickListener.java:39)
android.view.View.performClick (View.java:5204)
android.view.View$PerformClick.run (View.java:21153)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5420)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

As you can see from the second line of the log, -1 is being inserted as the rowId for the customer table when it should be 123 (123 is just an example, the rowId could be any number greater than 0).

EDIT: I'm starting to think that this guy might be poking around my app in ADB. That would explain why the intent extras aren't being delivered:

A user is somehow accessing Pro features in the Free version

Upvotes: 1

Views: 231

Answers (4)

Ashutosh Garg
Ashutosh Garg

Reputation: 31

Make sure you are not using any launchMode other than standard(default). If you are using launchMode attribute in receiving activity in Manifest file, then you have to deal with receiving activity accordingly (maybe you have to override onNewIntent method if activity already exist in the current task). For more information read this documentation - https://developer.android.com/guide/components/activities/tasks-and-back-stack

Upvotes: 2

Hemanth Gadi
Hemanth Gadi

Reputation: 93

If you are passing extras to an intent from Activity A and they are not received at the receiving Activity B onCreate() , then activity B already exists in android backstack and the extras are not caught in onCreate() but they can be found in onNewIntent() pls try below code:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    mCustomerId = getIntent().getLongExtra("customerId", -1);

}

Hope this will work for sure.

Upvotes: 1

Zankrut Parmar
Zankrut Parmar

Reputation: 1997

Try to do it like this:

    Intent intent = new Intent(MainActivity.this,Main2Activity.class);
    Long customerId = Long.valueOf(123);
    intent.putExtra("customerId", customerId);
    startActivity(intent);

Upvotes: 0

Rahul Kushwaha
Rahul Kushwaha

Reputation: 6732

Yes, You can do like this:-

In First Activity  ,customerId is in the long format.

Long customerId = 123;
intent.putExtra("customerId", customerId);
startActivity(intent);

But in Second Activity,do like this
long defaultVal= -1;
mCustomerId = getIntent().getLongExtra("customerId", defaultVal);

Perhaps ,This will give you a better solution.
   Thanks.

Upvotes: 0

Related Questions