-
-
Notifications
You must be signed in to change notification settings - Fork 475
fix(android-fragment): support detach/attach navigation in fragment tracing #5660
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
Open
romtsn
wants to merge
7
commits into
main
Choose a base branch
from
fix/fragment-detach-attach-tracing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+233
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55787df
fix(android-fragment): support detach/attach navigation in fragment t…
romtsn d861925
Format code
getsentry-bot a783845
Add changelog entry and detach/attach sample
romtsn af34cb1
Merge branch 'main' into fix/fragment-detach-attach-tracing
romtsn 0412cb7
Remove duplicate test methods in fragment lifecycle test
romtsn d5e4d9f
fix: Update screen name on scope for detach/attach fragment re-attach…
romtsn 27d39bd
Format code
getsentry-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...entry-samples-android/src/main/java/io/sentry/samples/android/DetachAttachTabsActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package io.sentry.samples.android | ||
|
|
||
| import android.os.Bundle | ||
| import android.view.View | ||
| import android.widget.TextView | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.fragment.app.commit | ||
|
|
||
| class DetachAttachTabsActivity : AppCompatActivity(R.layout.activity_detach_attach_tabs) { | ||
|
|
||
| private val tags = arrayOf("tab_a", "tab_b") | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
|
|
||
| findViewById<View>(R.id.btn_tab_a).setOnClickListener { showTab(0) } | ||
| findViewById<View>(R.id.btn_tab_b).setOnClickListener { showTab(1) } | ||
|
|
||
| if (savedInstanceState == null) { | ||
| val tabB = TabFragmentB() | ||
| supportFragmentManager.commit { | ||
| add(R.id.tab_container, TabFragmentA(), tags[0]) | ||
| add(R.id.tab_container, tabB, tags[1]) | ||
| detach(tabB) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun showTab(index: Int) { | ||
| supportFragmentManager.commit { | ||
| for (i in tags.indices) { | ||
| val frag = supportFragmentManager.findFragmentByTag(tags[i]) ?: continue | ||
| if (i == index) attach(frag) else detach(frag) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class TabFragmentA : Fragment(R.layout.fragment_tab) { | ||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| view.findViewById<TextView>(R.id.tab_label).text = "Tab A" | ||
| } | ||
| } | ||
|
|
||
| class TabFragmentB : Fragment(R.layout.fragment_tab) { | ||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| view.findViewById<TextView>(R.id.tab_label).text = "Tab B" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
sentry-samples/sentry-samples-android/src/main/res/layout/activity_detach_attach_tabs.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <LinearLayout | ||
| android:orientation="horizontal" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:padding="8dp"> | ||
|
|
||
| <Button | ||
| android:id="@+id/btn_tab_a" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="Tab A" /> | ||
|
|
||
| <Button | ||
| android:id="@+id/btn_tab_b" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="Tab B" /> | ||
| </LinearLayout> | ||
|
|
||
| <FrameLayout | ||
| android:id="@+id/tab_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="0dp" | ||
| android:layout_weight="1" /> | ||
| </LinearLayout> |
12 changes: 12 additions & 0 deletions
12
sentry-samples/sentry-samples-android/src/main/res/layout/fragment_tab.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/tab_label" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="center" | ||
| android:textSize="24sp" /> | ||
| </FrameLayout> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.