Skip to content

Commit 50c968b

Browse files
simplify use
1 parent 3c1c40f commit 50c968b

5 files changed

Lines changed: 20 additions & 29 deletions

File tree

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
自动存取Android Bundle中数据——给需要自动存取的变量添加注解,编译时会通过注解处理自动生成存取的代码
33

44
* Activity启动时自动取出Intent中的数据,并赋值给相应的field
5-
* Activity由于系统内存不足将要被杀死时,在onSaveInstanceState方法里存储数据,Activity重启时在onCreate中取出数据并赋值给相应的field
5+
* Activity或Fragment由于系统内存不足将要被杀死时,在onSaveInstanceState方法里存储数据,重启时在onCreate中取出数据并赋值给相应的field
66

77
```java
88
public class ExampleActivity extends Activity{
@@ -12,13 +12,6 @@ public class ExampleActivity extends Activity{
1212
@Override
1313
protected void onCreate(@Nullable Bundle savedInstanceState) {
1414
super.onCreate(savedInstanceState);
15-
//get data
16-
Bundle data;
17-
data = getIntent().getExtras();
18-
//judge data source
19-
if (data == null) {
20-
data = savedInstanceState;
21-
}
2215
DataAutoAccess.getData(this, data);
2316
//TODO use fields...
2417
}
@@ -65,8 +58,8 @@ Then, apply the 'android-apt' plugin in your module-level build.gradle and add t
6558
}
6659

6760
dependencies {
68-
compile 'com.thirtydegreesray:dataautoaccess:1.2.3'
69-
apt 'com.thirtydegreesray:dataautoaccess-compiler:1.2.3'
61+
compile 'com.thirtydegreesray:dataautoaccess:1.2.5'
62+
apt 'com.thirtydegreesray:dataautoaccess-compiler:1.2.5'
7063
}
7164

7265
##Proguard

dataautoaccess/src/main/java/com/thirtydegreesray/dataautoaccess/DataAutoAccess.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thirtydegreesray.dataautoaccess;
22

33

4+
import android.app.Activity;
45
import android.os.Build;
56
import android.os.Bundle;
67
import android.os.Parcelable;
@@ -20,13 +21,6 @@
2021
* {@literal @}Override
2122
* protected void onCreate(@Nullable Bundle savedInstanceState) {
2223
* super.onCreate(savedInstanceState);
23-
* //get data
24-
* Bundle data;
25-
* data = getIntent().getExtras();
26-
* //judge data source
27-
* if (data == null) {
28-
* data = savedInstanceState;
29-
* }
3024
* DataAutoAccess.getData(this, data);
3125
* //TODO use fields...
3226
* }
@@ -62,7 +56,17 @@ public class DataAutoAccess {
6256
* @param dataStore the bundle to get data
6357
*/
6458
public static void getData(Object targetObject, Bundle dataStore) {
65-
if (targetObject == null || dataStore == null) {
59+
60+
if(targetObject == null){
61+
return ;
62+
}
63+
64+
//data from savedInstanceState or intent
65+
if(targetObject instanceof Activity && dataStore == null){
66+
dataStore = ((Activity)targetObject).getIntent().getExtras();
67+
}
68+
69+
if (dataStore == null) {
6670
return;
6771
}
6872

gradle.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
# http://www.gradle.org/docs/current/userguide/build_environment.html
99

1010
# Specifies the JVM arguments used for the daemon process.
11-
# The setting is particularly useful for tweaking memory settings.
11+
# The setting is particularly
12+
#useful for tweaking memory settings.
1213
org.gradle.jvmargs=-Xmx1536m
1314

1415
# When configured, Gradle will run in incubating parallel mode.
1516
# This option should only be used with decoupled projects. More details, visit
1617
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1718
# org.gradle.parallel=true
1819

19-
VERSION_NAME = 1.2.3
20-
VERSION_CODE = 13
20+
VERSION_NAME = 1.2.5
21+
VERSION_CODE = 15
2122

gradlew

100644100755
File mode changed.

sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/BaseActivity.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ public class BaseActivity extends AppCompatActivity {
1414
@Override
1515
protected void onCreate(@Nullable Bundle savedInstanceState) {
1616
super.onCreate(savedInstanceState);
17-
//get data
18-
Bundle data;
19-
data = getIntent().getExtras();
20-
//judge data source
21-
if (data == null) {
22-
data = savedInstanceState;
23-
}
24-
DataAutoAccess.getData(this, data);
17+
DataAutoAccess.getData(this, savedInstanceState);
2518
}
2619

2720
@Override

0 commit comments

Comments
 (0)