1

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

Gavin Wright
  • 3,124
  • 3
  • 14
  • 35
  • Post logcat of that user's application. – Zankrut Parmar Sep 07 '18 at 04:06
  • @ZankrutParmar Posted, although there's no a lot to glean from it. – Gavin Wright Sep 07 '18 at 04:16
  • Hey @GavinWright, I am having a very similar situation as yours, with exactly the same device and Android version only. Were you able to find the reason? – Seven Jul 18 '19 at 02:56
  • 1
    @Seven The Nexus 4 running Android 6.0.1 is some sort of bot, either from Google or from a third party. Every time I update my app, Crashlytics shows me crashes from this device within a few hours. The device is located in Czechia, which is notable because my paid app has never been purchased in that country. It's a crawler bot that's programmatically viewing each Activity in my app, which would explain why the intent extras aren't there. So I think crashes from this device can be safely disregarded, although I'd still like to know what purpose it serves. – Gavin Wright Jul 18 '19 at 09:31
  • 1
    @GavinWright yeah that makes a lot of sense. I was able to reproduce the same stack traces as the ones reported in Crashlytics using `adb` to force a launch of each of the affected activities. Thank you very much! I was finally able to understand those super weird crashes. – Seven Jul 18 '19 at 15:16

4 Answers4

2

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

  • I'm using launchMode="singleTop" for my MainActivity (which is Activity A in the original post). So it's not the receiving activity. – Gavin Wright Sep 07 '18 at 06:01
1

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.

Hemanth Gadi
  • 93
  • 1
  • 4
  • This seems like a real possibility, although I'm not sure how the activity would get on the backstack multiple times. – Gavin Wright Sep 07 '18 at 05:16
0
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.
Rahul Kushwaha
  • 5,473
  • 3
  • 26
  • 30
0

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);
Zankrut Parmar
  • 1,872
  • 1
  • 13
  • 28