Skip to content

#Первое задание по activity#51

Open
Morozov0208Saveliy wants to merge 2 commits intoOtus-Android:masterfrom
Morozov0208Saveliy:develop
Open

#Первое задание по activity#51
Morozov0208Saveliy wants to merge 2 commits intoOtus-Android:masterfrom
Morozov0208Saveliy:develop

Conversation

@Morozov0208Saveliy
Copy link

No description provided.

<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.

@Morozov0208Saveliy , тут сингл-таск избыточен, и он не решит задачи 4. Объясню как сделать ниже - в обработчике нажатия

Log.i(TAG, "call onCreate ActvityA")
buttonA = findViewById(R.id.buttonAtoB)
buttonA?.setOnClickListener {
val intent = Intent(this, ActivityB::class.java)
Copy link

Choose a reason for hiding this comment

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

@Morozov0208Saveliy, тут нужно выполнить задание 2.1 - открыть В в отдельной задаче. У вас сейчас открывается в той же (это список последних запущенных):
same_task
Верное решение должно выглядеть примерно так:
different_tasks
Для того, чтобы запустить новый стек, я бы воспользовался флажками интента:
FLAG_ACTIVITY_MULTIPLE_TASK и FLAG_ACTIVITY_NEW_TASK
типа такого:

        buttonA?.setOnClickListener {
            val intent = Intent(this, ActivityB::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
            startActivity(intent)
        }

buttonToD = findViewById(R.id.act_C_to_Act_D)
buttonToD?.setOnClickListener {
finish()
val intent = 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.

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

closeStack = findViewById(R.id.close_stack)
closeStack?.setOnClickListener {
finish()
val intent = Intent(this, ActivityA::class.java)
Copy link

Choose a reason for hiding this comment

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

@Morozov0208Saveliy, можно воспользоваться методом 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