@@ -91,40 +91,36 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
9191
9292 @ Override
9393 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)
9695 }
9796
9897 @ Override
9998 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+
100112 final long now = System .currentTimeMillis ();
101113 executeInBackground (() -> captureLowMemoryBreadcrumb (now , level ));
102114 }
103115
104- private void captureLowMemoryBreadcrumb (final long timeMs , final @ Nullable Integer level ) {
116+ private void captureLowMemoryBreadcrumb (final long timeMs , final int level ) {
105117 if (scopes != null ) {
106118 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-
124119 breadcrumb .setType ("system" );
125120 breadcrumb .setCategory ("device.event" );
126121 breadcrumb .setMessage ("Low memory" );
127122 breadcrumb .setData ("action" , "LOW_MEMORY" );
123+ breadcrumb .setData ("level" , level );
128124 breadcrumb .setLevel (SentryLevel .WARNING );
129125 scopes .addBreadcrumb (breadcrumb );
130126 }
0 commit comments