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
16 changes: 11 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
}

android {
compileSdk 32
compileSdk 34

defaultConfig {
applicationId "otus.gpb.homework.activities"
minSdk 23
targetSdk 32
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -30,6 +30,10 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'otus.gpb.homework.activities'
buildFeatures {
viewBinding true
}
}

detekt {
Expand All @@ -49,7 +53,9 @@ tasks.named("detekt").configure {
}

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.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.activity:activity:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
26 changes: 23 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="otus.gpb.homework.activities">
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
Expand All @@ -12,6 +11,27 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Activities"
tools:targetApi="31" />
tools:targetApi="31">
<activity
android:name=".Activity_D"
android:exported="false" />
<activity
android:name=".Activity_C"
android:exported="false" />

<activity
android:name=".Activity_B"
android:exported="false" />
<activity
android:name=".Activity_A"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

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

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity


class Activity_A : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_a)
val button = findViewById<Button>(R.id.buttonA_to_B)
Log.d("Debug", "onCreateA")
}

fun onClickListener(view: View){ // создаем функцию и указываем переменную view типа View (!)
if (view is Button) {
// Создаем Intent для открытия другого Activity
val intent = Intent(this, Activity_B::class.java)
// Задание 2.1: Создаем FLAG_ACTIVITY_NEW_TASK для singleTop и добавляем флаг FLAG_ACTIVITY_MULTIPLE_TASK для открытия в новом таске
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
// Начинаем новое Activity
startActivity(intent)
}

}
// override fun onNewIntent(intent: Intent?) {
// super.onNewIntent(intent)
// }
// override fun onRestart() {
// super.onRestart()
// Log.d("Debug", "onRestart")
// val intent = Intent(this, Activity_A::class.java)
// intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
// startActivity(intent)
// Log.d("Debug", "onNewIntent")
// }



}
32 changes: 32 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/Activity_B.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package otus.gpb.homework.activities

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity


class Activity_B : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_b)
val button = findViewById<Button>(R.id.buttonB_to_C)
Log.d("Debug", "onCreateB")
}

override fun onDestroy() {
super.onDestroy()
Log.d("Debug", "onDestroyB")
}
fun onClickListener(view: View){ // создаем функцию и указываем переменную view типа View (!)
if (view is Button) {
Log.d("Debug", "openB")
// // Задание 2.2: Создаем Intent для открытия другого Activity
val intent = Intent(this, Activity_C::class.java)
// Начинаем новое Activity
startActivity(intent)
}
}
}
59 changes: 59 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/Activity_C.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package otus.gpb.homework.activities

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity


class Activity_C : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_c)
val button = findViewById<Button>(R.id.buttonC_to_A)
Log.d("Debug", "onCreateC")
}

override fun onResume() {
super.onResume()
Log.d("Debug", "onResumeC")
}
override fun onDestroy() {
super.onDestroy()
Log.d("Debug", "onDestroyC")
}
fun onClickListenerOpenAfromC(view: View) { // создаем функцию и указываем переменную view типа View (!)
if (view is Button) {
// Создаем Intent для открытия другого Activity
val intent = Intent(this, Activity_A::class.java)
// Начинаем новое Activity
startActivity(intent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Gimasteev, не выполняется задание 3.2. Оставил комментарий выше. Возможно, можно добиться того же эффекта с флагом FLAG_ACTIVITY_CLEAR_TOP

}
}

fun onClickListenerOpenDfromC(view: View){
val intent = Intent(this, Activity_D::class.java)
// Задание 2.4: Создаю новый активти и чищу весь стек. Вроде как сделано задание. Нажимаю назад и закрывается текущий таск, НО потом открываю трей и вижу, что оно есть))))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
}

fun onClickListenerCloseCAndGoBack(view: View){
val intent = Intent(this, Activity_B::class.java)
// Задание 2.5: Финиширую активити С
finish()
//intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
//startActivity(intent)
}

fun onClickListenerCloseStackAndGoA(view: View){
val intent = Intent(this, Activity_A::class.java)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Gimasteev, еще обратите внимание на функцию finishAffinity

// Задание 2.5: Финиширую через функцию finishAffinity(), но опять-таки вижу в трее что висит активити С
finishAffinity()
//intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
//startActivity(intent)
}

}
20 changes: 20 additions & 0 deletions app/src/main/java/otus/gpb/homework/activities/Activity_D.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package otus.gpb.homework.activities

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


class Activity_D : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_d)


}
fun onClickListener(view: View){ // создаем функцию и указываем переменную view типа View (!)

}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_a.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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:id="@+id/layoutActivityA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f44336"
android:onClick="onClickListener"
tools:context=".Activity_A">

<Button
android:id="@+id/buttonA_to_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickListener"
android:text="Open ActivityB"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_b.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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:id="@+id/layoutActivityB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4caf50"
android:onClick="onClickListener"
tools:context=".Activity_B">

<Button
android:id="@+id/buttonB_to_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickListener"
android:text="Open ActivityC"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
62 changes: 62 additions & 0 deletions app/src/main/res/layout/activity_c.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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:id="@+id/layoutActivityB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2196f3"
tools:context=".Activity_C">

<Button
android:id="@+id/buttonC_to_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="184dp"
android:onClick="onClickListenerOpenAfromC"
android:text="Open ActivityA"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />

<Button
android:id="@+id/buttonC_to_D"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="292dp"
android:onClick="onClickListenerOpenDfromC"
android:text="Open ActivityD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />

<Button
android:id="@+id/buttonC_close_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="388dp"
android:onClick="onClickListenerCloseCAndGoBack"
android:text="Close ActivityC"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.483"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />

<Button
android:id="@+id/buttonC_close_stack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="492dp"
android:onClick="onClickListenerCloseStackAndGoA"
android:text="Close Stack"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_d.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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:id="@+id/layoutActivityB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffeb3b"
tools:context=".Activity_D">

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">Activities</string>
<string name="app_name">Roman_Activities</string>
</resources>
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'com.android.application' version '8.4.0' apply false
id 'com.android.library' version '8.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
id "io.gitlab.arturbosch.detekt" version "1.21.0"
}

Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Loading