Skip to content

Comments

Homework 7#47

Open
dimangty wants to merge 3 commits intoOtus-Android:homeworks/activities_01from
dimangty:homeworks/activities_01
Open

Homework 7#47
dimangty wants to merge 3 commits intoOtus-Android:homeworks/activities_01from
dimangty:homeworks/activities_01

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