From 053e0ec2acf37c451a674251fa195351d8e4a143 Mon Sep 17 00:00:00 2001 From: Jakub Malinowski Date: Thu, 6 Jun 2024 17:35:28 +0200 Subject: [PATCH] Enable manual creation of screen view spans --- .../splunk/android/sample/FirstFragment.java | 14 ++++++ .../src/main/res/layout/fragment_first.xml | 6 +++ sample-app/src/main/res/values/strings.xml | 1 + .../rum/ExplicitVisibleScreenNameTracker.java | 39 +++++++++++++++ .../java/com/splunk/rum/NoOpSplunkRum.java | 7 ++- .../java/com/splunk/rum/RumInitializer.java | 14 +++++- .../main/java/com/splunk/rum/SplunkRum.java | 25 +++++++++- .../com/splunk/rum/NoOpSplunkRumTest.java | 3 ++ .../java/com/splunk/rum/SplunkRumTest.java | 48 +++++++++++++++++-- 9 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 splunk-otel-android/src/main/java/com/splunk/rum/ExplicitVisibleScreenNameTracker.java diff --git a/sample-app/src/main/java/com/splunk/android/sample/FirstFragment.java b/sample-app/src/main/java/com/splunk/android/sample/FirstFragment.java index 756cad25..0ef2cf92 100644 --- a/sample-app/src/main/java/com/splunk/android/sample/FirstFragment.java +++ b/sample-app/src/main/java/com/splunk/android/sample/FirstFragment.java @@ -80,6 +80,10 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { NavHostFragment.findNavController(FirstFragment.this) .navigate(R.id.action_FirstFragment_to_SecondFragment)); + binding.buttonScreenName.setOnClickListener(v -> { + SplunkRum.getInstance().setScreenName("custom-screen"); + }); + binding.crash.setOnClickListener(v -> multiThreadCrashing()); binding.httpMe.setOnClickListener( @@ -184,12 +188,22 @@ public LiveData getSessionId() { public void onDestroyView() { super.onDestroyView(); binding = null; + + SplunkRum.getInstance().setScreenName(null); } @Override public void onResume() { super.onResume(); sessionId.postValue(splunkRum.getRumSessionId()); + + SplunkRum.getInstance().setScreenName("custom-resumed-name", "Resumed"); + } + + @Override + public void onPause() { + super.onPause(); + SplunkRum.getInstance().setScreenName(null); } @SuppressLint("AllowAllHostnameVerifier") diff --git a/sample-app/src/main/res/layout/fragment_first.xml b/sample-app/src/main/res/layout/fragment_first.xml index af78e301..4267f023 100644 --- a/sample-app/src/main/res/layout/fragment_first.xml +++ b/sample-app/src/main/res/layout/fragment_first.xml @@ -42,6 +42,12 @@ android:layout_height="wrap_content" android:text="@string/next" /> +