Skip to content

Commit 4d46c26

Browse files
committed
Add task affinity sample
1 parent df36a2a commit 4d46c26

12 files changed

Lines changed: 111 additions & 38 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ dependencies {
6969
implementation fileTree(dir: 'libs', include: ['*.jar'])
7070
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
7171
implementation 'androidx.appcompat:appcompat:1.2.0'
72-
implementation 'androidx.core:core-ktx:1.5.0-alpha02'
73-
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
74-
implementation 'com.google.android.material:material:1.3.0-alpha02'
75-
implementation "androidx.biometric:biometric:1.0.1"
72+
implementation 'androidx.core:core-ktx:1.6.0-alpha02'
73+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
74+
implementation 'com.google.android.material:material:1.4.0-alpha02'
75+
implementation "androidx.biometric:biometric:1.1.0"
7676

77-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
78-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
79-
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha07'
80-
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
81-
implementation 'androidx.activity:activity-ktx:1.2.0-alpha08'
82-
implementation 'androidx.fragment:fragment-ktx:1.3.0-alpha08'
77+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
78+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
79+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01'
80+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
81+
implementation 'androidx.activity:activity-ktx:1.3.0-alpha07'
82+
implementation 'androidx.fragment:fragment-ktx:1.3.3'
8383

8484
implementation 'com.jakewharton.timber:timber:4.7.1'
8585

8686
testImplementation 'androidx.test:runner:1.3.0'
8787
testImplementation 'androidx.test.espresso:espresso-core:3.3.0'
8888
testImplementation 'androidx.test.ext:junit:1.1.2'
89-
testImplementation 'org.robolectric:robolectric:4.4'
90-
testImplementation 'com.willowtreeapps.assertk:assertk-jvm:0.22'
89+
testImplementation 'org.robolectric:robolectric:4.5.1'
90+
testImplementation 'com.willowtreeapps.assertk:assertk-jvm:0.23.1'
9191

9292
androidTestImplementation 'androidx.test:runner:1.3.0'
9393
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
android:supportsRtl="true"
1919
android:theme="@style/AppTheme"
2020
tools:ignore="GoogleAppIndexingWarning">
21-
<activity android:name=".constracts.CustomPermissionActivity"></activity>
21+
<activity
22+
android:name=".task.affinity.TaskAffinityActivity"
23+
android:taskAffinity=".TheOtherTask" />
24+
<activity android:name=".constracts.CustomPermissionActivity" />
2225
<activity android:name=".constracts.PermissionExampleActivity" />
2326

2427
<receiver
@@ -52,4 +55,4 @@
5255
</activity>
5356
</application>
5457

55-
</manifest>
58+
</manifest>

app/src/main/java/net/orgiu/tests/main/Functionalities.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import net.orgiu.tests.lce.LceActivity
1313
import net.orgiu.tests.networkrequest.NetworkRequestActivity
1414
import net.orgiu.tests.nightmode.NightModeActivity
1515
import net.orgiu.tests.snackbar.SnackbarActivity
16+
import net.orgiu.tests.task.affinity.TaskAffinityActivity
1617
import net.orgiu.tests.textscaling.TextScalingActivity
1718
import net.orgiu.tests.textscaling.TextScalingDataBindingOnlyActivity
1819

@@ -35,7 +36,8 @@ val functions = arrayOf(
3536
Functionality(R.string.fragment_lifecycle, FragmentListenerActivity::class.java),
3637
Functionality(R.string.lce, LceActivity::class.java),
3738
Functionality(R.string.contracts, ContractsActivity::class.java),
38-
Functionality(R.string.intent_sender, IntentSenderActivity::class.java)
39+
Functionality(R.string.intent_sender, IntentSenderActivity::class.java),
40+
Functionality(R.string.task_affinity, TaskAffinityActivity::class.java)
3941
)
4042

4143
fun AppCompatActivity.launchBy(functionality: Functionality<*>) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package net.orgiu.tests.task.affinity
2+
3+
import android.content.Intent
4+
import androidx.appcompat.app.AppCompatActivity
5+
import android.os.Bundle
6+
import net.orgiu.tests.R
7+
import net.orgiu.tests.databinding.ActivityTaskAffinityBinding
8+
import kotlin.properties.Delegates
9+
import kotlin.random.Random.Default.nextInt
10+
11+
class TaskAffinityActivity : AppCompatActivity() {
12+
13+
private var binding : ActivityTaskAffinityBinding by Delegates.notNull()
14+
private val charPool : List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')
15+
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
19+
binding = ActivityTaskAffinityBinding.inflate(layoutInflater)
20+
21+
setContentView(binding.root)
22+
23+
binding.btnNewActivity.setOnClickListener {
24+
startActivity(Intent(this, TaskAffinityActivity::class.java))
25+
}
26+
27+
binding.btnCloseAffinity.setOnClickListener {
28+
finishAffinity()
29+
}
30+
31+
binding.textView.text = generateRandomText()
32+
}
33+
34+
private fun generateRandomText(): CharSequence {
35+
val length = nextInt(0, 1000)
36+
return (1..length)
37+
.map { nextInt(0, charPool.size) }
38+
.map(charPool::get)
39+
.joinToString("")
40+
}
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".task.affinity.TaskAffinityActivity">
8+
9+
<TextView
10+
android:id="@+id/textView"
11+
android:layout_width="0dp"
12+
android:layout_height="0dp"
13+
android:layout_marginStart="16dp"
14+
android:layout_marginTop="16dp"
15+
android:layout_marginEnd="16dp"
16+
android:layout_marginBottom="16dp"
17+
android:text="TextView"
18+
app:layout_constraintBottom_toBottomOf="parent"
19+
app:layout_constraintEnd_toEndOf="parent"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent" />
22+
23+
<Button
24+
android:id="@+id/btnNewActivity"
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_marginStart="32dp"
28+
android:layout_marginEnd="32dp"
29+
android:layout_marginBottom="32dp"
30+
android:text="New Activity Of Same Task"
31+
app:layout_constraintBottom_toBottomOf="parent"
32+
app:layout_constraintEnd_toEndOf="parent"
33+
app:layout_constraintStart_toStartOf="parent" />
34+
35+
<Button
36+
android:id="@+id/btnCloseAffinity"
37+
android:layout_width="0dp"
38+
android:layout_height="wrap_content"
39+
android:layout_marginBottom="16dp"
40+
android:text="Close Affinity"
41+
app:layout_constraintBottom_toTopOf="@+id/btnNewActivity"
42+
app:layout_constraintEnd_toEndOf="@+id/btnNewActivity"
43+
app:layout_constraintStart_toStartOf="@+id/btnNewActivity" />
44+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
<string name="lce">LCE</string>
2929
<string name="contracts">Activity Results Contracts</string>
3030
<string name="intent_sender">Intent Sender</string>
31+
<string name="task_affinity">Task Affinity</string>
3132
</resources>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.4.0'
4+
ext.kotlin_version = '1.4.32'
55
repositories {
66
google()
77
jcenter()
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.2.0-alpha11'
11+
classpath 'com.android.tools.build:gradle:4.2.0-rc01'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
1414
classpath 'com.novoda:gradle-build-properties-plugin:0.4.1'

0 commit comments

Comments
 (0)