Skip to content

hw10 решение#44

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

hw10 решение#44
sergei-rodionov wants to merge 2 commits intoOtus-Android:masterfrom
sergei-rodionov:master

Conversation

@sergei-rodionov
Copy link

No description provided.

findViewById<Button?>(R.id.buttonA_openB).setOnClickListener{

val intent = Intent(this, ActivityB::class.java)
intent.flags = 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.

@sergei-rodionov , тут нужно сочетание флагов или аттрибут аффинити в манифесте. Парный флажок - FLAG_ACTIVITY_MULTIPLE_TASK, чтобы отключить проверки и безусловно открывать активити в новой задаче.
Вот запуск без этого флага - в истории один стек:
no_flag
А вот с этим флажком - стека два:
with_flags

setContentView(R.layout.activity_c)
findViewById<Button?>(R.id.buttonC_openA).setOnClickListener{
val intent = Intent(this, ActivityA::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or
Copy link

Choose a reason for hiding this comment

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

Мне кажется, тут можно без флажков. Параметр манифеста у активити А singleTask сделает свое дело.

Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(intent)
finish()

Copy link

Choose a reason for hiding this comment

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

Тут можно использовать метод finishAffinity. Работает с 16го АПИ

<activity
android:name=".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.

В принципе, можно использовать и стандартный режим. Вы правильно расставили флажки при запуске.

@sergei-rodionov
Copy link
Author

Скорректировал код.

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