ScreenTracker
is a lightweight utility for tracking which screen (Activity or Fragment) is currently visible in your Android application. It works automatically, leveraging lifecycle callbacks to ensure seamless integration without requiring manual logging in every screen.
- Automatic Screen Tracking: Automatically monitors and tracks the currently active
Activity
andFragment
. - Memory Safe: Uses
WeakReference
to ensure there are no memory leaks. - Analytics Integration: Optional support for Firebase Analytics to log screen views.
- Lightweight: Designed for large projects with minimal performance overhead.
- Simple API: Provides easy access to the current screen name.
- Framework-Compatible: Works with XML and Jetpack Compose-based applications.
Ensure the following dependencies are added in your settings.gradle.kts
file:
pluginManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }// Add this line
}
}
Ensure the following dependencies are added in your build.gradle.kts
file:
dependencies {
implementation ("com.github.hassanwasfy:iTell:${leatest_version}")
}
Add the following code to your Application
class to start tracking activities and fragments globally:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize the ScreenTracker
//remember to add this line ONLY in DEBUG mode
if (BuildConfig.DEBUG){
ScreenTrackerInitializer().initialize(this)
}
}
}
You can retrieve the name of the currently active screen (Activity or Fragment) using:
val currentScreenName = ScreenTracker.getCurrentScreenName()
Log.d("ScreenTracker", "Current Screen: $currentScreenName")
If you use Firebase Analytics, initialize it in ScreenTracker
dynamically (if available) to log screen views:
ScreenTracker.initializeFirebase(context)
- Seamless Integration: No need to manually invoke
ScreenTracker
in each screen; lifecycle callbacks handle tracking automatically. - Memory Management: Ensure memory safety using the built-in
WeakReference
implementation. - Analytics Integration: Use the optional Firebase Analytics integration to log screen views for better user experience monitoring.
- Debugging Aid: Utilize
ScreenTracker
logs to debug navigation issues or monitor screen transitions. - Scope Limitations: Be mindful of nested fragments or dynamically added fragments. Modify callbacks if necessary to support these.
Yes, but you may need to extend the implementation to support childFragmentManager
for nested fragments.
Yes, it works with Jetpack Compose-based activities and fragments.
No, the use of WeakReference
ensures that references to activities and fragments do not cause memory leaks.
Yes, Firebase Analytics is optional and can be skipped entirely if not needed.
This project is licensed under a dual-license model:
- Personal/Non-Commercial Use:
- Licensed under a free, non-commercial license.
- For personal and educational use only.
- Commercial use needs approval.
By using this software, you agree to the terms of the appropriate license.
ScreenTracker
is an essential utility for tracking user navigation in Android apps, offering simplicity, efficiency, and flexibility. Whether for debugging or analytics, it seamlessly integrates into your app with minimal setup.