Skip to content

Added homework #7 solving#48

Open
drugpamir wants to merge 2 commits intoOtus-Android:masterfrom
drugpamir:master
Open

Added homework #7 solving#48
drugpamir wants to merge 2 commits intoOtus-Android:masterfrom
drugpamir:master

Conversation

@drugpamir
Copy link

No description provided.

android:name=".ActivityB"
android:label="ActivityB"
android:exported="false"
android:launchMode="singleTask"/>
Copy link

Choose a reason for hiding this comment

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

@drugpamir , здесь singleTask сам по себе не поможет, если taskAffinity у активити одинаковый. Вот результат запуска активити Б с вашим вариантом:
1stacks

А должно быть вот так:
2stacks

Забегая вперед, скажу, что вы правильно догадались про флажки в запуске активити Б, но там нужно сочетание. Напишу ниже

buttonToB = findViewById(R.id.button_a)
buttonToB?.setOnClickListener {
intent = Intent(this, ActivityB::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Copy link

Choose a reason for hiding this comment

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

Тут не хватает флажка FLAG_ACTIVITY_MULTIPLE_TASK. Тогда Б запустится в новом стеке, а аттрибут в манифесте не нужен.

android:name=".ActivityD"
android:label="ActivityD"
android:exported="false"
android:launchMode="singleTask"/>
Copy link

Choose a reason for hiding this comment

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

Тут тоже достаточно стандартного режима - см. ниже


buttonOpenD = findViewById(R.id.button_open_d)
buttonOpenD?.setOnClickListener {
startActivity(Intent(this, ActivityD::class.java))
Copy link

Choose a reason for hiding this comment

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

@drugpamir , для того, чтобы очистить текущий стек от того, что в нем сейчас, можно воспользоваться сочетанием флагов:
FLAG_ACTIVITY_CLEAR_TASK и FLAG_ACTIVITY_NEW_TASK


buttonCloseStack = findViewById(R.id.button_close_stack)
buttonCloseStack?.setOnClickListener {
intent = Intent(this, ActivityA::class.java).apply {
Copy link

Choose a reason for hiding this comment

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

Тут я бы предложил воспользоваться функцией finishAffinity. История - это немного другая история :) Не имеет отношения к таскам и стекам, а только регулирует то, что у нас видно в списке последних приложений. А теперь вы понимаете, что там не приложения, на самом деле, а активити.

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

Comments