Skip to content

Commit 45b02c1

Browse files
committed
jetpack app-startup demo.
1 parent 5db702e commit 45b02c1

38 files changed

Lines changed: 875 additions & 0 deletions

Jetpack-AppStartup-Demo/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.2"
8+
9+
defaultConfig {
10+
applicationId "cn.yan.appstartup"
11+
minSdkVersion 21
12+
targetSdkVersion 30
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
implementation "androidx.startup:startup-runtime:1.0.0"
33+
implementation 'androidx.appcompat:appcompat:1.2.0'
34+
implementation 'com.google.android.material:material:1.2.1'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36+
testImplementation 'junit:junit:4.+'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cn.yan.appstartup;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("cn.yan.appstartup", appContext.getPackageName());
25+
}
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="cn.yan.appstartup">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/Theme.JetpackAppStartupDemo">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
21+
<provider
22+
android:name="androidx.startup.InitializationProvider"
23+
android:authorities="${applicationId}.androidx-startup"
24+
android:exported="false"
25+
tools:node="merge">
26+
<!-- This entry makes ExampleLoggerInitializer discoverable. -->
27+
<meta-data android:name="cn.yan.appstartup.Binitializer"
28+
android:value="androidx.startup" />
29+
<meta-data android:name="cn.yan.appstartup.Cinitializer"
30+
android:value="androidx.startup" />
31+
<meta-data android:name="cn.yan.appstartup.DasAinitializer"
32+
android:value="androidx.startup" />
33+
</provider>
34+
</application>
35+
36+
</manifest>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cn.yan.appstartup;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.startup.Initializer;
8+
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
/**
13+
* @author yanbo1
14+
*/
15+
public class Ainitializer implements Initializer<Object> {
16+
private static final String TAG = "Initializer";
17+
18+
@NonNull
19+
@Override
20+
public Object create(@NonNull Context context) {
21+
Log.d(TAG, "Ainitializer create...");
22+
return new Object();
23+
}
24+
25+
@NonNull
26+
@Override
27+
public List<Class<? extends Initializer<?>>> dependencies() {
28+
Log.d(TAG, "Ainitializer dependencies");
29+
30+
return Arrays.asList(Cinitializer.class);
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cn.yan.appstartup;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.startup.Initializer;
8+
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
* @author yanbo1
14+
*/
15+
public class Binitializer implements Initializer<Object> {
16+
private static final String TAG = "Initializer";
17+
18+
@NonNull
19+
@Override
20+
public Object create(@NonNull Context context) {
21+
Log.d(TAG, "Binitializer create...");
22+
return new Object();
23+
}
24+
25+
@NonNull
26+
@Override
27+
public List<Class<? extends Initializer<?>>> dependencies() {
28+
Log.d(TAG, "Binitializer dependencies");
29+
return Collections.emptyList();
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cn.yan.appstartup;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.startup.Initializer;
8+
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
* @author yanbo1
14+
*/
15+
public class Cinitializer implements Initializer<Object> {
16+
private static final String TAG = "Initializer";
17+
18+
@NonNull
19+
@Override
20+
public Object create(@NonNull Context context) {
21+
Log.d(TAG, "Cinitializer create...");
22+
return new Object();
23+
}
24+
25+
@NonNull
26+
@Override
27+
public List<Class<? extends Initializer<?>>> dependencies() {
28+
Log.d(TAG, "Cinitializer dependencies");
29+
return Collections.emptyList();
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cn.yan.appstartup;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.startup.Initializer;
8+
9+
import java.util.Arrays;
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
/**
14+
* @author yanbo1
15+
*/
16+
public class DasAinitializer extends Ainitializer {
17+
private static final String TAG = "Initializer";
18+
19+
@NonNull
20+
@Override
21+
public Object create(@NonNull Context context) {
22+
Log.d(TAG, "DasAinitializer create...");
23+
return super.create(context);
24+
}
25+
26+
@NonNull
27+
@Override
28+
public List<Class<? extends Initializer<?>>> dependencies() {
29+
Log.d(TAG, "DasAinitializer dependencies");
30+
return Arrays.asList(Binitializer.class);
31+
}
32+
}

0 commit comments

Comments
 (0)