Skip to content

Commit 3676ee9

Browse files
author
xiaoqi
committed
update to 2.1.0
1 parent e01460c commit 3676ee9

15 files changed

Lines changed: 405 additions & 245 deletions

File tree

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
2.0.2 修复通过继承去实现Serializable的对象不能识别的bug;
2020
2.0.3 优化异常提示
2121
2.0.4 修复枚举类型保存的时候不能识别的问题
22+
23+
2.1.0 增加对PersistableBundle的支持,NeedSave注解中设置isPersistable = true则说明该参数保存到PersistableBundle
2224

2325

2426
引入方式,在app的gradle中加入下面依赖即可:
2527

2628

27-
compile 'com.noober:savehelper:2.0.4'
28-
compile 'com.noober:savehelper-api:2.0.4'
29-
annotationProcessor 'com.noober:processor:2.0.4'
29+
implementation 'com.noober:savehelper:2.1.0'
30+
implementation 'com.noober:savehelper-api:2.1.0'
31+
annotationProcessor 'com.noober:processor:2.1.0'
3032

3133
# 引入
3234

@@ -239,5 +241,30 @@ savedInstanceState不会null的时候,说明就是需要内存恢复的时候
239241
# 总结
240242
看到这里大家已经猜到其实这个框架的实现原理和BufferKnife是相同的。而bufferknife的原理很多文章都有,这里就不过多介绍了。
241243

244+
# 更新
245+
## 2.1.0
246+
增加对PersistableBundle持久化数据的保存,用于手机关机重启后的数据恢复,使用方法如下:
247+
248+
249+
@NeedSave(isPersistable = true)
250+
PersistableBundle persistableBundle;
251+
252+
@NeedSave(isPersistable = true)
253+
int i;
254+
255+
@Override
256+
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
257+
super.onCreate(savedInstanceState, persistentState);
258+
SaveHelper.recover(this, savedInstanceState, persistentState);
259+
}
260+
261+
@Override
262+
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
263+
SaveHelper.save(this, outState, outPersistentState);
264+
super.onSaveInstanceState(outState, outPersistentState);
265+
}
266+
267+
268+
242269
github地址:[https://github.com/JavaNoober/AutoSave](https://github.com/JavaNoober/AutoSave)
243270

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ext {
3535
userOrg = 'noober'
3636
groupId = 'com.noober'
3737
uploadName = 'AutoSaver'
38-
publishVersion = '2.0.4'
38+
publishVersion = '2.1.1'
3939
desc = "A light weight framework can automatically generate 'OnSaveInstanceState' code"
4040
website = 'https://github.com/JavaNoober/AutoSave'
4141
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
1212
#org.gradle.jvmargs=-Xmx1536m
13-
org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006
13+
org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
1414
org.gradle.parallel=true
1515
# When configured, Gradle will run in incubating parallel mode.
1616
# This option should only be used with decoupled projects. More details, visit

sample/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ dependencies {
2929
})
3030
implementation 'com.android.support:appcompat-v7:26.1.0'
3131
testImplementation 'junit:junit:4.12'
32-
implementation 'com.noober:savehelper:2.0.4'
33-
annotationProcessor 'com.noober:processor:2.0.4'
34-
implementation 'com.noober:savehelper-api:2.0.4'
35-
// implementation project(':savehelper')
36-
// implementation project(':savehelper-api')
37-
// annotationProcessor project(':savehelper-processor')
32+
implementation 'com.noober:savehelper:2.1.0'
33+
annotationProcessor 'com.noober:processor:2.1.0'
34+
implementation 'com.noober:savehelper-api:2.1.0'
35+
// implementation project(':savehelper')
36+
// implementation project(':savehelper-api')
37+
// annotationProcessor project(':savehelper-processor')
3838
}

sample/src/main/AndroidManifest.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
android:label="@string/app_name"
88
android:theme="@style/Theme.AppCompat.NoActionBar"
99
android:supportsRtl="true">
10-
<activity android:name=".SampleActivity">
11-
</activity>
12-
<activity android:name=".TestActivity">
10+
<activity android:name=".SampleActivity"
11+
android:persistableMode="persistAcrossReboots">
1312
<intent-filter>
1413
<action android:name="android.intent.action.MAIN"/>
1514

1615
<category android:name="android.intent.category.LAUNCHER"/>
1716
</intent-filter>
1817
</activity>
18+
<activity android:name=".TestActivity">
19+
</activity>
1920
</application>
2021

2122
</manifest>
Lines changed: 88 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.recover.autosavesample;
22

3+
import android.os.PersistableBundle;
4+
import android.support.annotation.Nullable;
35
import android.support.v7.app.AppCompatActivity;
46
import android.os.Bundle;
7+
import android.util.Log;
58
import android.util.Size;
69
import android.util.SizeF;
710
import android.util.SparseArray;
@@ -14,76 +17,107 @@
1417

1518
public class SampleActivity extends AppCompatActivity {
1619

17-
@NeedSave
18-
String test;
19-
@NeedSave
20-
public boolean b;
21-
@NeedSave
22-
protected Boolean c;
23-
@NeedSave
24-
ArrayList<String> t;
25-
@NeedSave
26-
Integer i;
27-
@NeedSave
28-
ParcelableExample parcelableExample;
29-
@NeedSave
30-
Float f1;
31-
@NeedSave
32-
float f2;
33-
@NeedSave
34-
char achar;
35-
@NeedSave
36-
char achars[];
37-
@NeedSave
38-
int sssss[];
39-
@NeedSave
40-
int[] sasa;
41-
@NeedSave
42-
Bundle bundle;
43-
@NeedSave
44-
int a;
45-
@NeedSave
46-
SerializableExample serializableExample;
47-
48-
@NeedSave
49-
ArrayList<SerializableExample> serializableExamples;
50-
@NeedSave
51-
ArrayList<ParcelableExample> parcelableExamples;
52-
@NeedSave
53-
ParcelableExample[] parcelableArray;
54-
@NeedSave
55-
SparseArray<ParcelableExample> sparseArray;
56-
@NeedSave
57-
byte[] bytes;
58-
@NeedSave
59-
String[] stringArray;
60-
@NeedSave
61-
long[] longArray;
62-
@NeedSave
63-
Size size;
20+
// @NeedSave
21+
// String test;
22+
// @NeedSave
23+
// public boolean b;
24+
// @NeedSave
25+
// protected Boolean c = false;
26+
// @NeedSave
27+
// ArrayList<String> t;
28+
// @NeedSave
29+
// Integer i;
30+
// @NeedSave
31+
// ParcelableExample parcelableExample;
32+
// @NeedSave
33+
// Float f1;
34+
// @NeedSave
35+
// float f2;
36+
// @NeedSave
37+
// char achar;
38+
// @NeedSave
39+
// char achars[];
40+
// @NeedSave
41+
// int sssss[];
42+
// @NeedSave
43+
// int[] sasa;
44+
// @NeedSave
45+
// Bundle bundle;
46+
// @NeedSave
47+
// int a;
48+
// @NeedSave
49+
// SerializableExample serializableExample;
50+
//
51+
// @NeedSave
52+
// ArrayList<SerializableExample> serializableExamples;
53+
// @NeedSave
54+
// ArrayList<ParcelableExample> parcelableExamples;
55+
// @NeedSave
56+
// ParcelableExample[] parcelableArray;
57+
// @NeedSave
58+
// SparseArray<ParcelableExample> sparseArray;
59+
// @NeedSave
60+
// byte[] bytes;
61+
// @NeedSave
62+
// String[] stringArray;
63+
// @NeedSave
64+
// long[] longArray;
65+
// @NeedSave
66+
// Size size;
6467
@NeedSave
6568
SizeF sizeFS;
6669

67-
@NeedSave
68-
SecondSExample secondSExample;
70+
@NeedSave
71+
Bundle bundle;
72+
73+
//
74+
// @NeedSave
75+
// SecondSExample secondSExample;
6976

7077
// @NeedSave
7178
// SecondSExample2 secondSExample2;
79+
80+
81+
7282
@Override
7383
protected void onCreate(Bundle savedInstanceState) {
7484
super.onCreate(savedInstanceState);
7585
setContentView(R.layout.activity_main);
7686
initData();
87+
Log.e("Sample", i + "");
88+
if(savedInstanceState != null){
89+
i = savedInstanceState.getInt("ttt");
90+
Log.e("Sample", "onCreate1:" + i);
91+
}
7792
SaveHelper.recover(this,savedInstanceState);
7893
}
7994

8095
private void initData() {
8196
//TODO
8297
}
8398

84-
@Override
85-
protected void onSaveInstanceState(Bundle outState) {
86-
SaveHelper.save(this,outState);
87-
super.onSaveInstanceState(outState);
88-
}
99+
@Override
100+
protected void onSaveInstanceState(Bundle outState) {
101+
Log.e("Sample", "onSaveInstanceState");
102+
SaveHelper.save(this,outState);
103+
super.onSaveInstanceState(outState);
104+
}
105+
106+
@NeedSave(isPersistable = true)
107+
PersistableBundle persistableBundle;
108+
109+
@NeedSave(isPersistable = true)
110+
int i;
111+
112+
@Override
113+
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
114+
super.onCreate(savedInstanceState, persistentState);
115+
SaveHelper.recover(this, savedInstanceState, persistentState);
116+
}
117+
118+
@Override
119+
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
120+
SaveHelper.save(this, outState, outPersistentState);
121+
super.onSaveInstanceState(outState, outPersistentState);
122+
}
89123
}

sample/src/main/java/com/recover/autosavesample/TestActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.recover.autosavesample;
22

3+
import android.content.Intent;
34
import android.os.Bundle;
45
import android.util.SparseArray;
56
import android.view.View;
@@ -40,6 +41,9 @@ protected void onCreate(Bundle savedInstanceState) {
4041
public void onClick(View v) {
4142
testString = "222222222";
4243
textView.setText(testContent + testString);
44+
Intent intent = new Intent(TestActivity.this, SampleActivity.class);
45+
intent.putExtra("test", 1);
46+
startActivity(intent);
4347
}
4448
});
4549
}

savehelper-api/src/main/java/com/noober/api/NeedSave.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
@Retention(RetentionPolicy.SOURCE)
1010
public @interface NeedSave {
1111

12+
boolean isPersistable() default false;
1213
}

0 commit comments

Comments
 (0)