Skip to content

Fragment#2

Closed
C00lness wants to merge 2 commits intoAndroid-Developer-Basic:masterfrom
C00lness:master
Closed

Fragment#2
C00lness wants to merge 2 commits intoAndroid-Developer-Basic:masterfrom
C00lness:master

Conversation

@C00lness
Copy link
Copy Markdown

@C00lness C00lness commented Dec 9, 2022

No description provided.

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

</activity>
Copy link
Copy Markdown

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")
Copy link
Copy Markdown

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()
}
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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(
Copy link
Copy Markdown

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.
Copy link
Copy Markdown

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