Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
22 changes: 21 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Activities"
tools:targetApi="31" />
tools:targetApi="31">
<activity
android:name=".ActivityD"
android:exported="false" />
<activity
android:name=".ActivityC"
android:exported="false" />
<activity
android:name=".ActivityB"
android:exported="false" />
<activity
android:name=".ActivityA"
android:launchMode="singleTask"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
21 changes: 21 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/ActivityA.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package otus.gpb.homework.activities

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class ActivityA : AppCompatActivity(R.layout.activity_a) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

findViewById<Button>(R.id.open_activity_b_btn).setOnClickListener { runActivityB() }
}

private fun runActivityB() {
val intent = Intent(this, ActivityB::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
}
startActivity(intent)
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/ActivityB.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package otus.gpb.homework.activities

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class ActivityB : AppCompatActivity(R.layout.activity_b) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

findViewById<Button>(R.id.open_activity_c_btn).setOnClickListener { runActivityC() }
}

private fun runActivityC() {
val intent = Intent(this, ActivityC::class.java)
startActivity(intent)
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/ActivityC.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package otus.gpb.homework.activities

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class ActivityC : AppCompatActivity(R.layout.activity_c) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

findViewById<Button>(R.id.close_stack_btn).setOnClickListener { closeTask() }
findViewById<Button>(R.id.open_activity_a_btn).setOnClickListener { openActivityA() }
findViewById<Button>(R.id.open_activity_d_btn).setOnClickListener { openActivityD() }
findViewById<Button>(R.id.close_activity_c_btn).setOnClickListener { closeActivityC() }
}

private fun openActivityA() {
val intent = Intent(this, ActivityA::class.java)
startActivity(intent)
}

private fun openActivityD() {
val intent = Intent(this, ActivityD::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
}
startActivity(intent)
}

private fun closeActivityC() {
finish()
}

private fun closeTask() {
finishAffinity()
val intent = Intent(this, ActivityA::class.java)
startActivity(intent)
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/ActivityD.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package otus.gpb.homework.activities

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class ActivityD : AppCompatActivity(R.layout.activity_d) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_a.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f44336"
tools:context=".ActivityA">

<Button
android:id="@+id/open_activity_b_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Open Activity B"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</androidx.constraintlayout.widget.ConstraintLayout>
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_b.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4caf50"
tools:context=".ActivityB">

<Button
android:id="@+id/open_activity_c_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Open Activity C"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</androidx.constraintlayout.widget.ConstraintLayout>
47 changes: 47 additions & 0 deletions app/src/main/res/layout/activity_c.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2196f3"
tools:context=".ActivityC">

<Button
android:id="@+id/open_activity_a_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Open Activity A"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/open_activity_d_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/open_activity_a_btn"
android:text="Open Activity D"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/close_activity_c_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/open_activity_d_btn"
android:text="Close Activity C"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/close_stack_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/close_activity_c_btn"
android:text="Close Stack"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</androidx.constraintlayout.widget.ConstraintLayout>
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_d.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffeb3b"
tools:context=".ActivityD">

</androidx.constraintlayout.widget.ConstraintLayout>