-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash NPE while manually tracking views using a Lifecycle observer #439
Comments
Hi @yamilmedina, Thank you for bringing this to our attention. I’m sorry to hear that you’re encountering a NullPointerException (NPE) with our SDK. To help us investigate this issue further, could you please share the configuration code block you’re using for initializing the Countly SDK? Additionally, could you let us know if you’re using the halt or stop methods of the SDK at any point in your implementation? |
Thanks @arifBurakDemiray ! This is the config block we use.
|
Hi @yamilmedina, Thank you for sharing your configuration code—it looks great! It seems the NullPointerException (NPE) you’re encountering is related to the use of the halt function. Please note that the halt function is intended for testing purposes only and should not be used in production builds. This is because it clears all SDK states, requiring the Countly SDK to be re-initialized afterward. Essentially, using halt behaves as if the app has been completely terminated. If your goal is to disable tracking, I recommend revoking all consents instead. This is a safer and more suitable approach for production environments. You can achieve this by using the following method: Countly.sharedInstance().consent().removeConsentAll(); This will disable all tracking without requiring the SDK to be re-initialized. If you have any questions or need further clarification, feel free to reach out. We’re here to help! |
Thanks again, one question thought about.
Does this mean if we use EDIT: Sorry we reinit already, so it should be fine, thanks again |
@arifBurakDemiray coming back again with feedback. It is still crashing with the same stacktrace. So using This happens while calling on stop.
|
Hello @yamilmedina, sorry for late response. Yes if removeConsentAll used, giveConsent must be used. And above log indicates that WireActivity's onStart is not called. Could you please validate that? |
Also, I noticed something I missed earlier—if you’d like to use consents, you’ll need to enable consent management first. You can find more details about this in the Countly Android SDK documentation here: Additionally, I’d like to mention that the Countly SDK automatically registers for activity lifecycle callbacks if the Application class is provided. It listens to the onStart and onStop callbacks to track views. In my experience, the SDK works seamlessly with Jetpack Compose projects, as it is able to catch those views effectively. |
While, we can initialize the Countly SDK and use the tracking system for activities and events.
There is one case where the SDK is simply crashing internally and with that the Application.
It seems to me by looking at the logs there is a missing context in the internals.
Expected Behavior
We should be able to interact with the app, send it to the background, come back, and independently of the state of the SDK, initialized, halted, etc. It should not bubble up a NPE to the consumer app.
Current Behavior
We are receiving a NPE, triggering a crash.
Logs (if appropriate)
Possible Solution
Just simply don't NPE 🙏
More Description
Given we are using Jetpack compose in our project and not the view system, we need to track the screens in the app.
We have a lifecycle observer in the App, that every time it comes to the foreground, it will track the current activity by calling
onStart
activity. The same when the app is sent to the background, we callonStop
.Your Environment
The text was updated successfully, but these errors were encountered: