-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSimpleFixed.java
73 lines (61 loc) · 2.38 KB
/
JSimpleFixed.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.text.TextUtils;
import java.util.UUID;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.LruCache;
/**
* java version
* <a href="https://juejin.cn/post/7306388118914973734">Thanks</a>
*/
public class JSimpleFixed {
private static final String KEY = "TransactionTooLargeOptKey";
private static LruCache<String, Bundle> map = new LruCache<>(32);
public void init(Application application) {
application.registerActivityLifecycleCallbacks(new DefaultActivityLifecycleCallbacks() {
@Override
public void onActivityPostSaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
String uuid = UUID.randomUUID().toString();
Bundle newBundle = new Bundle();
newBundle.putAll(outState);
map.put(uuid, newBundle);
outState.clear();
outState.putString(KEY, uuid);
}
@Override
public void onActivityPreCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
if (savedInstanceState == null) return;
String uuid = savedInstanceState.getString(KEY);
if (TextUtils.isEmpty(uuid)) return;
Bundle bundle = map.get(uuid);
savedInstanceState.clear();
savedInstanceState.putAll(bundle);
}
});
}
public static class JDefaultActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(@NonNull Activity activity) {
}
@Override
public void onActivityResumed(@NonNull Activity activity) {
}
@Override
public void onActivityPaused(@NonNull Activity activity) {
}
@Override
public void onActivityStopped(@NonNull Activity activity) {
}
@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
}
@Override
public void onActivityDestroyed(@NonNull Activity activity) {
}
}
}