Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Fragment#2

Closed
C00lness wants to merge 2 commits intoAndroid-Developer-Basic:masterAndroid-Developer-Basic/Fragments:masterfrom
C00lness:masterCopy head branch name to clipboard
Closed

Fragment#2
C00lness wants to merge 2 commits intoAndroid-Developer-Basic:masterAndroid-Developer-Basic/Fragments:masterfrom
C00lness:masterCopy head branch name to clipboard

Conversation

@C00lness
Copy link

@C00lness C00lness commented Dec 9, 2022

No description provided.

android:name=".MainActivity"
android:exported="true">

</activity>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно добавить еще один активити к примеру сделать 2 кнопки с переходом MainActivity на MainActivity_A и MainActivity на MainActivity_B

view.findViewById<Button>(R.id.OpenFragment_AA).setOnClickListener{
val Fr_AA = Fragment_AA()
childFragmentManager.beginTransaction()
.replace(R.id.FrameLayout_AA, Fr_AA, "Fr_AA")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно использовать parentFragmentManager, так он даст выполнить еще условие пункт 4 в задании

override fun handleOnBackPressed() {
Log.v("TAG", "Dispatcher working...")
parentFragmentManager.popBackStack()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут можно проверить сколько фрагментов остался во фрагмент менеджере как описано в пункте 4 задачи
примерно так
if(количество фрагментов > 1 )
parentFragmentManager.popBackStack()
else
requireActivity().finish()

}
requireActivity().onBackPressedDispatcher.addCallback(
this,
callback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь коллбек OnBackPressedCallback не нужен, он уже есть в Fragment_A при нажатии назад он будет отрабатывать

parentFragmentManager.popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь тоже можно убрать коллбек OnBackPressedCallback

* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Также рекомендую очистить лишние коментарии и код который генерит студиа при создании фрагментов, чтоб повысить читабельность кода

iskino added a commit to iskino/Fragments that referenced this pull request Jun 30, 2023
@C00lness C00lness closed this by deleting the head repository Oct 23, 2023
Morozov0208Saveliy added a commit to Morozov0208Saveliy/Fragments that referenced this pull request Aug 1, 2024
Lofter23rus added a commit to Lofter23rus/Fragments that referenced this pull request Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.