Search code examples
androidandroid-activity

callingPackageName is coming null for release variant of application


I am using startActivityForResult and launching an activity say DestActivity. In DestActivity, callingPackageName is coming null for release variant but coming fine for debug variant. Any idea why it might be happening? Minify is enabled for both release as well as debug variants.


Solution

  • I faced this issue on the android Set Top Box of one the telecom companies. Issue was that DestActivity was launching properly with startActivityForResult() from another activity. In DestActivity callingPackage was coming properly as I read it in onCreate() for debug build. But for release build, callingPackage was coming null.

    When I did a little more digging into, it appeared that callingPackage was nullable value and something was making it null for release build after first access. Hence instead of using it directly, I created a local variable to hold value of callingPackage and than used that local variable wherever needed. Surprisingly it worked like a charm.