-
Notifications
You must be signed in to change notification settings - Fork 57
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
base: master
Are you sure you want to change the base?
Changes from all commits
458b6cb
19084a8
4616948
65055e4
cd09fac
8bb7604
cdc3074
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".ActivityC" | ||
android:label="ActivityC" | ||
android:launchMode="singleTop" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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") | ||
} | ||
} | ||
|
||
|
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) | ||
} | ||
|
||
} | ||
} |
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
} | ||
} |
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) | ||
|
||
} | ||
} |
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> |
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> |
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> |
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Galinnka , зачем вам тут сингл-таск? Вы все верно флажками разрулили в создании интентов!