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

Домашняя работа по активити 1 задача #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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'
}
30 changes: 29 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@
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:label="ActivityD"
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.

@Galinnka , зачем вам тут сингл-таск? Вы все верно флажками разрулили в создании интентов!

android:exported="false" />
<activity
android:name=".ActivityC"
android:label="ActivityC"
android:launchMode="singleTop"
Copy link

Choose a reason for hiding this comment

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

@Galinnka , поясните, пожалуйста, зачем вам сингл-топ?

android:exported="false" />
<activity
android:name=".ActivityB"
android:label="ActivityB"
android:launchMode="standard"
android:exported="false" />
<activity
android:name=".ActivityA"
android:exported="true"
android:launchMode="standard"
Copy link

Choose a reason for hiding this comment

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

@Galinnka , тут у вас неверный режим активити. Не выполняется задание 2.3, а создается новый экземпляр

android:taskAffinity=""
android:label="ActivityA">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
66 changes: 66 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,66 @@
package otus.gpb.homework.activities

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


private const val TAG = "ActivityA"

class ActivityA : AppCompatActivity(R.layout.activity_a) {

lateinit var buttonB: Button

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "call onCreate")

buttonB = findViewById(R.id.mainActivityB)
}

override fun onStart() {
super.onStart()
Log.d(TAG, "call onStart")
buttonB.setOnClickListener {
Log.d(TAG, "button clicked")
val intent = Intent(this, ActivityB::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
}
startActivity(intent)
}
}

override fun onResume() {
super.onResume()
Log.d(TAG, "call onResume")
}

override fun onStop() {
Log.d(TAG, "call onStop")
super.onStop()
}

override fun onDestroy() {
Log.d(TAG, "call onDestroy")
super.onDestroy()
}

override fun onRestart() {
super.onRestart()
Log.d(TAG, "call onRestart")
}

override fun onBackPressed() {
Log.d(TAG, "call onBackPressed")
super.onBackPressed()
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.d(TAG, "call onNewIntent")
}
}


25 changes: 25 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,25 @@
package otus.gpb.homework.activities

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

private const val TAG = "ActivityB"

class ActivityB : AppCompatActivity(R.layout.activity_b) {

lateinit var buttonC: Button

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)


findViewById<Button?>(R.id.mainActivityC).setOnClickListener {
val intent = Intent(this, ActivityC::class.java)
startActivity(intent)
}

}
}
54 changes: 54 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,54 @@
package otus.gpb.homework.activities

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

private const val TAG = "ActivityC"

class ActivityC : AppCompatActivity(R.layout.activity_c) {

lateinit var buttonA: Button
lateinit var buttonD: Button
lateinit var buttonC: Button
lateinit var buttonS: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

buttonA = findViewById(R.id.mainActivityA)
buttonD = findViewById(R.id.mainActivityD)
buttonC = findViewById(R.id.mainActivityC)
buttonS = findViewById(R.id.closeStack)
}


override fun onStart() {
super.onStart()
Log.d(TAG, "call onStart")
buttonA.setOnClickListener {
Log.d(TAG, "button clicked")
val intent = Intent(this, ActivityA::class.java)
startActivity(intent)
}
findViewById<Button>(R.id.mainActivityD).setOnClickListener {
val intent = Intent(this, ActivityD::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
}

startActivity(intent)
}
buttonC.setOnClickListener {
finish()
}
buttonS.setOnClickListener {
finishAffinity()
Copy link

Choose a reason for hiding this comment

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

@Galinnka , тут все верно. Стек закрывается и попадаем обратно на А. Если вам кажется, что он не закрылся потому, что торчит в последних запущенных программах - то это норм. потому что это список ПОСЛЕДНИХ ЗАПУЩЕННЫХ, а не тех, что сейчас в памяти

}
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.d(TAG, "button onNewIntent")
}
}
13 changes: 13 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,13 @@
package otus.gpb.homework.activities

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

private const val TAG = "ActivityD"

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

}
}
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"?>
<FrameLayout
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/mainActivityB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open ActivityB"
android:layout_margin="50dp"
android:layout_gravity="bottom|center_horizontal"
/>



</FrameLayout>
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"?>
<LinearLayout
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:orientation="vertical"
android:gravity="center"
android:background="#4caf50"
tools:context=".ActivityB">

<Button
android:id="@+id/mainActivityC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Activity C"
android:layout_margin="50dp"
android:layout_gravity="bottom|center_horizontal"
/>

</LinearLayout>
45 changes: 45 additions & 0 deletions app/src/main/res/layout/activity_c.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:gravity="center"
android:background="#2196f3"
tools:context=".ActivityC">

<Button
android:id="@+id/mainActivityA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#FFC107"
android:backgroundTint="#CDDC39"
android:text="Open ActivityA" />

<Button
android:id="@+id/mainActivityD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Open ActivityD" />

<Button
android:id="@+id/mainActivityC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Close ActivityC" />

<Button
android:id="@+id/closeStack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Close Stack"
/>


</LinearLayout>
24 changes: 24 additions & 0 deletions app/src/main/res/layout/activity_d.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffeb3b"
android:gravity="center_horizontal"
tools:context=".ActivityD">


<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="Улыбнись! Это Activity D"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>