launchdarkly / android-client-sdk

LaunchDarkly Client-side SDK for Android
Other
45 stars 23 forks source link

LaunchDarkly causing GcmBroadcastReceiver issue when using it along OneSignal. #73

Closed RHMDHDYT closed 5 years ago

RHMDHDYT commented 5 years ago

Description: So, i'm using onesignal for notification and launchdarkly for feature flagging in my app. And i found that when the app closed (by swiping from recent apps) the device can't get notification. Another scenario like receiving notification when the app is active and receiving notification when the app in the stand by mode (pressing back button) is working fine.

In logcat i see that the notification was delivered to the device but canceled. 2019-05-14 12:02:02.405 21243-21243/? W/GCM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=id.qasir.mitra.staging (has extras) }

After tracing the code and removing some dependencies that may contains notification services / broadcast receiver, i found that the problem is from launchdarkly. I'm still learning launchdarkly source code and not yet find the issue.

To make sure that "notification not shown issue" is not from the OS, i'm trying the OneSignal example app and its working fine in same device.

So, my temporary solution right now is by removing launchdarkly from my app and replacing the feature flag with firebase remote config. Both library (Onesignal and LaunchDarkly) are important to me and can't replaced with other libraries.

Any help will be appreciated.

Environment

Android Compile SDK Version: 28 Build Tools Version: 28.0.3 Kotlin Version: 1.3.31 OneSignal Gradle plugin: [0.12.1, 0.99.99] OneSignal library: 3.10.8 Launchdarkly: 2.8.0

Device testing:

Steps to Reproduce Issue:

  1. Implement Onesignal using this step https://documentation.onesignal.com/docs/android-sdk-setup 2.Implement Launchdarkly using this step https://docs.launchdarkly.com/docs/android-sdk-reference
  2. Then launch the app
  3. Close the app by swiping from recent app
  4. Send notification to device
gwhelanLD commented 5 years ago

Hi RHMDHDYT,

Thanks for the detailed issue report. This issue may take some extra time to investigate as it's about a potential interaction with an external library and service. We'll update this issue as soon as we know more.

gwhelanLD commented 5 years ago

I have followed the steps to reproduce, but have not been able to observe the issue reported.

Steps I took:

  1. Created a new Android project
  2. Created a Firebase project for it
  3. Integrated Onesignal according to documentation
  4. Integrated LaunchDarkly according to our documentation
  5. Update gradle dependency versions to match environment
  6. Failed to reproduce the issue in the emulator.

In order to help us reproduce this issue could you answer the following questions?

  1. Was testing performed against a fresh project, or only against an existing project with other dependencies?
  2. Have you been able to reproduce this issue on an emulator, or only on physical devices?
  3. Where is your project are you initializing LaunchDarkly and OneSignal?

Thank you for your assistance in tracking down this issue.

RHMDHDYT commented 5 years ago

Hi @gwhelanLD

  1. i tested on existing and fresh project.
  2. yes
  3. i initialize both on application class and listen LD receiver on baseActivity

here i upload a sample project to help you tracing the issue. https://github.com/RHMDHDYT/SampleApp

gwhelanLD commented 5 years ago

I appreciate the prompt answers to my questions and the very helpful sample project for replication. I have been able to reproduce the issue and will update you as soon as I know more about the root cause.

Thanks.

gwhelanLD commented 5 years ago

The cause of your issue seems to be the line ldClient = LDClient.init(this, ldConfig, user, 0) in CustomApplication.kt. I believe the intent was to not wait for completion of the client initialization before continuing, however LDClient.init with a startWaitSeconds of zero actually indicates to wait until completion. When an application is started to respond to a broadcast intent, it is given a very short period of time to initialize. Additionally, the completion of the init future may be delayed as the SDK will detect that it has been started in the background. This causes the application to trigger an ANR before it can handle the notification intent.

To trigger an init without waiting for completion try the following:

LDClient.init(this, ldConfig, user)
ldClient = LDClient.get()

In my testing this prevents the ANR issue, and push notifications when the application has been stopped work correctly. Let me know if this solves the issue for you.

Thanks again for the issue report and helpful sample project.

RHMDHDYT commented 5 years ago

Yes it solve my issue. by init the LDClient using your way or adding startWaitSeconds in 5 second now the notification working properly.

Many thanks @gwhelanLD