यह त्रुटि स्मृति रिसाव के मामले में हुई। उदाहरण के लिए यदि आपके पास एंड्रॉइड घटक (गतिविधि / सेवा / आदि) का कोई स्थिर संदर्भ है और सिस्टम द्वारा मारा जाता है।
उदाहरण: अधिसूचना क्षेत्र में संगीत खिलाड़ी नियंत्रण। नीचे की तरह PendingIntent के माध्यम से एक अग्रभूमि सेवा का उपयोग करें और अधिसूचना चैनल में क्रियाएं सेट करें।
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);
और अगर यह सूचना चैनल अचानक टूट जाता है (सिस्टम द्वारा हो सकता है, जैसे कि श्याओमी डिवाइस जब हम बैकग्राउंड ऐप्स को साफ करते हैं), तो मेमोरी लीक के कारण यह त्रुटि सिस्टम द्वारा फेंक दी जाती है।