So I am translating my application but I am facing annoying problem.
I have a service with foreground notification with 2 action buttons.
When I select the language in the main activity,the app works great with the translation strings.However,lets say I choose english and the service notification started,the notification text is in english for the first time,but when I get back to the application and minimize the app again,the text of the service notification is changed to the other language without me doing anything.
Service detect language code ( onCreate ):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (MainActivity.LANG_CURRENT.equals("en")) { changeLang(getApplicationContext(),"en"); } else { changeLang(getApplicationContext(),"iw"); } }
Service Notification code:
channelName = "Background Service"; NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH); chan.setLightColor(Color.BLUE); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); assert manager != null; manager.createNotificationChannel(chan); Intent intentExit = new Intent(this, BackgroundLocation.class); intentExit.putExtra(EXIT_APP_NOTI, true); sendBroadcast(intentExit); // The PendingIntent that leads to a call to onStartCommand() in this service. PendingIntent servicePendingIntent = PendingIntent.getService(this, 0, intentExit, PendingIntent.FLAG_CANCEL_CURRENT); Intent i = new Intent(getApplicationContext(), MapsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent activityPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (MainActivity.LANG_CURRENT.equals("en")) { changeLang(getApplicationContext(),"en"); } else { changeLang(getApplicationContext(),"iw"); } } NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_launch, getString(R.string.launch), activityPendingIntent); NotificationCompat.Action action2 = new NotificationCompat.Action(R.drawable.ic_cancel, getString(R.string.stop), servicePendingIntent); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) .setContentTitle("App is running in background") .addAction(action) .addAction(action2) .setColor(getColor(R.color.foreGroundBackgroundColor)) .setPriority(NotificationManager.IMPORTANCE_HIGH) .setCategory(Notification.CATEGORY_SERVICE) .setSmallIcon(R.drawable.applogo) .build(); startForeground(2, notification);
Thank you for your help !