Skip to content
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

Homework 7 #47

Open
wants to merge 3 commits into
base: homeworks/activities_01
Choose a base branch
from

Conversation

dimangty
Copy link

@dimangty dimangty commented May 8, 2024

No description provided.

android:exported="false" />
<activity
android:name=".ActivityA"
android:exported="true">
Copy link

Choose a reason for hiding this comment

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

@dimangty , тут вы упустили launchMode, чтобы выполнялось задание 3. Мы должны попадать в прежний экземпляр активити А.
Чтобы убедиться в том, что задание выполняется, рекомендую добавить в активити А переопределение метода:

override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
}

Можно поставить в нем точку останова или сделать логирование
Сейчас активити открывается во втором стеке
activitya

}

binding.openDButton.setOnClickListener {
finishAffinity()
Copy link

Choose a reason for hiding this comment

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

Тут лучше использовать не finishAffinity, а очищать текущий стек флагами:

        binding.openDButton.setOnClickListener {
            val intent= Intent(this, ActivityD::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
            startActivity(intent)
        }

Подробнее можно почитать тут
Сравните стеки.
Вот ваш вариант (старый стек уничтожился, открылся новый):
activityd
А вот с флажками (старый стек ОЧИСТИЛСЯ и в нем открылась новая активность):
activitydcorrect

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