-
Notifications
You must be signed in to change notification settings - Fork 56
add realisation activity A, B, C, D #31
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
Open
DariaMandzyuk
wants to merge
2
commits into
Otus-Android:homeworks/activities_01
Choose a base branch
from
DariaMandzyuk:homeworks/activities_01
base: homeworks/activities_01
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,4 @@ run.sh | |
| *.aab | ||
| output-metadata.json | ||
| /build.properties | ||
| *.hprof | ||
| *.hprof | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /build | ||
| /build | ||
| /.gradle/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/ru/otus/otusdemo/ExampleInstrumentedTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
|
||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| import org.junit.Assert.* | ||
|
|
||
| /** | ||
| * Instrumented test, which will execute on an Android device. | ||
| * | ||
| * See [testing documentation](http://d.android.com/tools/testing). | ||
| */ | ||
| @RunWith(AndroidJUnit4::class) | ||
| class ExampleInstrumentedTest { | ||
| @Test | ||
| fun useAppContext() { | ||
| // Context of the app under test. | ||
| val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
| assertEquals("ru.otus.otusdemo", appContext.packageName) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,50 @@ | ||
| <?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"> | ||
| package="ru.otus.otusdemo"> | ||
|
|
||
| <application | ||
| android:name=".OtusApplication" | ||
| android:allowBackup="true" | ||
| android:dataExtractionRules="@xml/data_extraction_rules" | ||
| android:fullBackupContent="@xml/backup_rules" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:roundIcon="@mipmap/ic_launcher_round" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/Theme.Activities" | ||
| tools:targetApi="31" /> | ||
| android:theme="@style/Theme.OtusDemo" | ||
| tools:targetApi="31"> | ||
| <activity | ||
| android:name=".ActivityD" | ||
| android:exported="false" /> | ||
| <activity | ||
| android:name=".ActivityC" | ||
| android:exported="false" /> | ||
| <activity | ||
| android:name=".ActivityB" | ||
| android:launchMode="standard" | ||
| android:taskAffinity="" | ||
| android:exported="false" /> | ||
| <activity | ||
| android:name=".ActivityA" | ||
| android:launchMode="singleTask" | ||
| android:taskAffinity="" | ||
| android:exported="true" > | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
|
|
||
| </manifest> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity | ||
| android:name=".MainActivity" | ||
| android:exported="true" | ||
| android:launchMode="standard"> | ||
| </activity> | ||
| <activity | ||
| android:name=".SecondActivity" | ||
| android:exported="false" | ||
| android:launchMode="singleTask" /> | ||
| </application> | ||
|
|
||
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.widget.Button | ||
| import android.widget.Toast | ||
|
|
||
| class ActivityA : AppCompatActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_a) | ||
|
|
||
| val button = findViewById<Button>(R.id.act_a_button_open_to_act_B) | ||
| button.setOnClickListener { | ||
| val intent = Intent(applicationContext, ActivityB::class.java) | ||
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
| startActivity(intent) | ||
| } | ||
| } | ||
|
|
||
| override fun onNewIntent(intent: Intent?) { | ||
| super.onNewIntent(intent) | ||
| Toast.makeText(this, "мы попали на существующий экземпляр ActivityA", Toast.LENGTH_SHORT) | ||
| .show() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.widget.Button | ||
| import android.widget.Toast | ||
|
|
||
| @Suppress("DEPRECATION") | ||
| class ActivityB : AppCompatActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_b) | ||
| val button = findViewById<Button>(R.id.act_b_button_open_to_act_C) | ||
|
|
||
| button.setOnClickListener { | ||
| val intent = Intent(applicationContext, ActivityC::class.java) | ||
| startActivity(intent) | ||
| } | ||
| } | ||
|
|
||
| override fun onBackPressed() { | ||
| super.onBackPressed() | ||
| Toast.makeText(this, "Кнопка бэк была нажата", Toast.LENGTH_SHORT).show() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.widget.Button | ||
| import android.widget.Toast | ||
|
|
||
| @Suppress("DEPRECATION") | ||
| class ActivityC : AppCompatActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_c) | ||
|
|
||
| val button1 = findViewById<Button>(R.id.act_c_button_to_act_a) | ||
| button1.setOnClickListener { | ||
| val intent = Intent(applicationContext, ActivityA::class.java) | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| val button2 = findViewById<Button>(R.id.act_c_button_to_act_d) | ||
| button2.setOnClickListener { | ||
| val intent = Intent(applicationContext, ActivityD::class.java) | ||
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
| intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| val button3 = | ||
| findViewById<Button>(R.id.act_c_close_act_c) // По клику на кнопку “CloseActivityC”, завершите ActivityC, и перейдите на предыдущий экран в стеке | ||
| button3.setOnClickListener { | ||
| finish() | ||
| // val intent = Intent(applicationContext, ActivityB::class.java) | ||
| // startActivity(intent) | ||
| } | ||
|
|
||
| val button4 = | ||
| findViewById<Button>(R.id.act_c_close_stack) // По клику на кнопку “Close Stack” завершите текущий стек, в котором находятся ActivityB и ActivityC, и перейдите на ActivityA | ||
| button4.setOnClickListener { | ||
| finishAffinity() | ||
| val intent = Intent(applicationContext, ActivityA::class.java) | ||
| startActivity(intent) | ||
| } | ||
| } | ||
|
|
||
| override fun onBackPressed() { | ||
| super.onBackPressed() | ||
| Toast.makeText(this, "Кнопка бэк была нажата", Toast.LENGTH_SHORT).show() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.widget.Button | ||
| import android.widget.Toast | ||
|
|
||
| @Suppress("DEPRECATION") | ||
| class ActivityD : AppCompatActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_d) | ||
|
|
||
| val button1 = findViewById<Button>(R.id.act_d_button) | ||
| button1.setOnClickListener { | ||
| Toast.makeText(this, "ТОЧНО END!", Toast.LENGTH_SHORT).show() | ||
| } | ||
| } | ||
|
|
||
| override fun onNewIntent(intent: Intent?) { | ||
| super.onNewIntent(intent) | ||
| Toast.makeText(this, "onNewIntent", Toast.LENGTH_SHORT).show() | ||
| } | ||
|
|
||
| override fun onBackPressed() { | ||
| super.onBackPressed() | ||
| Toast.makeText(this, "Кнопка бэк была нажата", Toast.LENGTH_SHORT).show() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.widget.Button | ||
| import androidx.appcompat.app.AppCompatActivity | ||
|
|
||
| class MainActivity : AppCompatActivity() { | ||
|
|
||
| // вызывается в момент инициализиации экрана | ||
| // и служит для задания системных параметров, файла верстки | ||
| // Вызывается перед отрисовкой экрана, верстка создана, но экран не отобразился | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_main) | ||
| } | ||
|
|
||
| // Вызывается после отрисовки экрана, но пользователь в момент вызова еще не может | ||
| // взаимодействовать с интерфейсом | ||
| override fun onStart() { | ||
| super.onStart() | ||
| val button = findViewById<Button>(R.id.buttonSecondActivity) | ||
| button.setOnClickListener { | ||
|
|
||
| // val id = (applicationContext as OtusApplication).id | ||
| // Toast.makeText(this, "Кнопка бэк была нажата", Toast.LENGTH_SHORT).show() | ||
|
|
||
| val intent = Intent(applicationContext, SecondActivity::class.java) | ||
| startActivity(intent) | ||
| } | ||
| } | ||
|
|
||
| // Весь экран отрисован, готов к работе, пользователю доступно взаимодействие с интерфейсом | ||
| override fun onResume() { | ||
| super.onResume() | ||
| } | ||
|
|
||
| //У пользователя пропадает возможность взаимодействовать с интерфейсом, хотя экран еще виден | ||
| override fun onPause() { | ||
| super.onPause() | ||
| } | ||
|
|
||
| // Экран уже не виден | ||
| override fun onStop() { | ||
| super.onStop() | ||
| // отменить все запросы кеоторые были отправлены но не дошли | ||
| } | ||
|
|
||
| // Наша активити уничтожена и больше нет ее в памяти | ||
| override fun onDestroy() { | ||
| super.onDestroy() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.app.Application | ||
|
|
||
| class OtusApplication : Application() { | ||
|
|
||
|
|
||
| val id = "Im from Application" | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ru.otus.otusdemo | ||
|
|
||
| import android.content.Intent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.widget.Button | ||
| import android.widget.Toast | ||
|
|
||
| class SecondActivity : AppCompatActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_second) | ||
| val button = findViewById<Button>(R.id.secondActivityButton) | ||
| button.setOnClickListener { | ||
| val intent = Intent(applicationContext, SecondActivity::class.java) | ||
| startActivity(intent) | ||
| } | ||
| } | ||
|
|
||
| override fun onNewIntent(intent: Intent?) { | ||
| super.onNewIntent(intent) | ||
| Toast.makeText(this, "onNewIntent", Toast.LENGTH_SHORT).show() | ||
| } | ||
|
|
||
| override fun onBackPressed() { | ||
| super.onBackPressed() | ||
| Toast.makeText(this, "Кнопка бэк была нажата", Toast.LENGTH_SHORT).show() | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/ru/otus/otusdemo/examples/ContractMainActivityAndSecondActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package ru.otus.otusdemo.examples | ||
|
|
||
| import android.app.Activity | ||
| import android.content.Context | ||
| import android.content.Intent | ||
| import androidx.activity.result.contract.ActivityResultContract | ||
| import ru.otus.otusdemo.MainActivity | ||
|
|
||
| class ContractMainActivityAndSecondActivity : ActivityResultContract<String, String?>() { | ||
|
|
||
| override fun createIntent(context: Context, input: String): Intent { | ||
| //return Intent(context, SecondActivity::class.java).apply { | ||
| return Intent(context, MainActivity::class.java).apply { | ||
| putExtra("currentName", input) | ||
| } | ||
| } | ||
|
|
||
| override fun parseResult(resultCode: Int, intent: Intent?): String? { | ||
| if (intent == null) return null | ||
| if (resultCode != Activity.RESULT_OK) return null | ||
|
|
||
| return intent.getStringExtra("resultKey") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@DariaMandzyuk , так не получится открыть новый таск.
Нужно или в манифесте установить таск аффинити отличный от А или использовать флаги:
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK