Skip to content

Commit 7ef5ba5

Browse files
committed
Add a trace button to the second activity
1 parent 1bf8120 commit 7ef5ba5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/FirstFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FirstFragment : Fragment() {
7171
}
7272
}
7373
binding.createTrace.setOnClickListener {
74-
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
74+
lifecycleScope.launch(Dispatchers.IO) {
7575
val performanceTrace = performance.newTrace("test_trace")
7676
performanceTrace.start()
7777
delay(1000)

firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/SecondActivity.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
2222
import android.os.Build
2323
import android.os.Bundle
2424
import android.widget.Button
25+
import androidx.lifecycle.lifecycleScope
26+
import com.google.firebase.perf.FirebasePerformance
27+
import kotlinx.coroutines.delay
28+
import kotlinx.coroutines.launch
2529

2630
/** Second activity from the MainActivity that runs on a different process. */
2731
class SecondActivity : BaseActivity() {
28-
2932
override fun onCreate(savedInstanceState: Bundle?) {
3033
super.onCreate(savedInstanceState)
3134
setContentView(R.layout.activity_second)
@@ -38,6 +41,15 @@ class SecondActivity : BaseActivity() {
3841
findViewById<Button>(R.id.second_crash_button).setOnClickListener {
3942
throw IllegalStateException("SecondActivity has crashed")
4043
}
44+
findViewById<Button>(R.id.second_create_trace).setOnClickListener {
45+
lifecycleScope.launch {
46+
val performanceTrace = FirebasePerformance.getInstance().newTrace("test_trace")
47+
performanceTrace.start()
48+
delay(1000)
49+
performanceTrace.stop()
50+
}
51+
52+
}
4153
findViewById<Button>(R.id.kill_background_processes).setOnClickListener {
4254
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
4355
getSystemService(ActivityManager::class.java)

firebase-sessions/test-app/src/main/res/layout/activity_second.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
app:layout_constraintTop_toBottomOf="@id/prev_activity_button"
3939
app:layout_constraintLeft_toLeftOf="parent" />
4040

41+
<Button
42+
android:id="@+id/second_create_trace"
43+
android:layout_width="wrap_content"
44+
android:layout_height="wrap_content"
45+
android:text="@string/create_trace"
46+
app:layout_constraintTop_toBottomOf="@id/second_crash_button"
47+
app:layout_constraintLeft_toLeftOf="parent" />
48+
4149
<Button
4250
android:id="@+id/kill_background_processes"
4351
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)