Bu hata, bellek sızıntısı durumunda meydana geldi. Örneğin, bir Android bileşeninin (Etkinlik / hizmet / vb.) Statik bağlamınız varsa ve sistem tarafından öldürülürse.
Örnek: Bildirim alanındaki müzik çalar kontrolleri. Bir ön plan hizmeti kullanın ve aşağıdaki gibi PendingIntent aracılığıyla bildirim kanalında eylemler ayarlayın.
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction(AppConstants.ACTION.MAIN_ACTION);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Intent previousIntent = new Intent(this, ForegroundService.class);
previousIntent.setAction(AppConstants.ACTION.PREV_ACTION);
PendingIntent ppreviousIntent = PendingIntent.getService(this, 0,
previousIntent, 0);
Intent playIntent = new Intent(this, ForegroundService.class);
playIntent.setAction(AppConstants.ACTION.PLAY_ACTION);
PendingIntent pplayIntent = PendingIntent.getService(this, 0,
playIntent, 0);
Intent nextIntent = new Intent(this, ForegroundService.class);
nextIntent.setAction(AppConstants.ACTION.NEXT_ACTION);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel.
notificationChannel.setDescription("Channel description");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder
.setOngoing(true)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setContentTitle("Foreground Service")
.setContentText("Foreground Service Running")
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
.setContentIntent(pendingIntent)
.setPriority(NotificationManager.IMPORTANCE_MAX)
.setCategory(Notification.CATEGORY_SERVICE)
.setTicker("Hearty365")
.build();
startForeground(AppConstants.NOTIFICATION_ID.FOREGROUND_SERVICE,
notification);
Ve bu bildirim kanalı aniden bozulursa (arka plan uygulamalarını temizlediğimizde Xiomi cihazlarında olduğu gibi sistem tarafından olabilir), bellek sızıntıları nedeniyle bu hata sistem tarafından atılır.