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

Activity 1 #50

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

Conversation

RubaN0id
Copy link

No description provided.

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

@RubaN0id, мне кажется, singleTask тут лишний. Во втором стеке активити у нас просто ложатся друг на друга. Или есть другие соображения?

android:name=".BActivity"
android:exported="false"
android:launchMode="singleTask" />
<activity
Copy link

Choose a reason for hiding this comment

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

@RubaN0id, singleInstance тут не подойдет, потому что делает невозможным выполнение пункта 2.1:

при этом предусмотрите возможность открывать другие Activity в том же стеке где расположена ActivityA

Вот документация по флагам. Там есть удобная табличка.

val bButton: Button = findViewById(R.id.button_to_B)
bButton.text = getString(R.string.open_activity_b)
bButton.setOnClickListener {
startActivity(Intent(this, BActivity::class.java))
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 и FLAG_ACTIVITY_NEW_TASK.
Если все правильно настроено, то в списке последних запущенных вы явно увидите два стека - с А и Б

setContentView(R.layout.activity_c)
val dButton: Button = findViewById(R.id.button_to_D)
dButton.setOnClickListener {
finishAffinity()
Copy link

Choose a reason for hiding this comment

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

Здесь тоже можно не закрывать стек целиком, а просто очистить текущий при помощи таких флагов:
FLAG_ACTIVITY_NEW_TASK и FLAG_ACTIVITY_CLEAR_TASK.
Это так, на всякий случай. Кроме того, 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