@@ -91,40 +91,36 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
91
91
92
92
@ Override
93
93
public void onLowMemory () {
94
- final long now = System .currentTimeMillis ();
95
- executeInBackground (() -> captureLowMemoryBreadcrumb (now , null ));
94
+ // we do this in onTrimMemory below already, this is legacy API (14 or below)
96
95
}
97
96
98
97
@ Override
99
98
public void onTrimMemory (final int level ) {
99
+ if (level < TRIM_MEMORY_BACKGROUND ) {
100
+ // only add breadcrumb if TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_MODERATE or
101
+ // TRIM_MEMORY_COMPLETE.
102
+ // Release as much memory as the process can.
103
+
104
+ // TRIM_MEMORY_UI_HIDDEN, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_RUNNING_LOW and
105
+ // TRIM_MEMORY_RUNNING_CRITICAL.
106
+ // Release any memory that your app doesn't need to run.
107
+ // So they are still not so critical at the point of killing the process.
108
+ // https://developer.android.com/topic/performance/memory
109
+ return ;
110
+ }
111
+
100
112
final long now = System .currentTimeMillis ();
101
113
executeInBackground (() -> captureLowMemoryBreadcrumb (now , level ));
102
114
}
103
115
104
- private void captureLowMemoryBreadcrumb (final long timeMs , final @ Nullable Integer level ) {
116
+ private void captureLowMemoryBreadcrumb (final long timeMs , final int level ) {
105
117
if (scopes != null ) {
106
118
final Breadcrumb breadcrumb = new Breadcrumb (timeMs );
107
- if (level != null ) {
108
- // only add breadcrumb if TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_MODERATE or
109
- // TRIM_MEMORY_COMPLETE.
110
- // Release as much memory as the process can.
111
-
112
- // TRIM_MEMORY_UI_HIDDEN, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_RUNNING_LOW and
113
- // TRIM_MEMORY_RUNNING_CRITICAL.
114
- // Release any memory that your app doesn't need to run.
115
- // So they are still not so critical at the point of killing the process.
116
- // https://developer.android.com/topic/performance/memory
117
-
118
- if (level < TRIM_MEMORY_BACKGROUND ) {
119
- return ;
120
- }
121
- breadcrumb .setData ("level" , level );
122
- }
123
-
124
119
breadcrumb .setType ("system" );
125
120
breadcrumb .setCategory ("device.event" );
126
121
breadcrumb .setMessage ("Low memory" );
127
122
breadcrumb .setData ("action" , "LOW_MEMORY" );
123
+ breadcrumb .setData ("level" , level );
128
124
breadcrumb .setLevel (SentryLevel .WARNING );
129
125
scopes .addBreadcrumb (breadcrumb );
130
126
}
0 commit comments