Estoy haciendo una notificación que cuando el usuario abre la aplicación me envía una notificación en ese mismo instante, cuando se cambie el valor en un TextView notifique de nuevo pero el problema es que cuando el usuario abre la aplicación 2 o 3 veces con el mismo valor me sigue mostrando las notificaciones. Es posible notificar una sola vez hasta que se cambie de valor en un TextView?. He investigado que se puede hacer con Firebase pero quiero hacerlo en la misma aplicación, adjunto mi código .java
public void obtenerData() {
RequestQueue requestQueue = Volley.newRequestQueue(Objects.requireNonNull(getActivity()).getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST, DATA_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
TextView max;
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("datos");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
textValor.setText(jsonObject1.getString("valor"));
if(!textValor.getText().equals("4.9")){
createNotification();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
requestQueue.add(stringRequest);
}
void createNotification(){
NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity().getApplicationContext(), CHANNEL_ID);
builder.setSmallIcon(R.drawable.ic_menu_send);
builder.setContentTitle("Notificacion del dia");
builder.setContentText("Valor cambiado");
builder.setColor(Color.BLUE);
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setLights(Color.MAGENTA, 1000, 1000);
builder.setVibrate(new long[]{1000,1000,1000,1000,1000});
builder.setDefaults(Notification.DEFAULT_SOUND);
builder.setContentIntent(pendingIntent);
builder.addAction(R.drawable.ic_menu_send, "VER INMEDIATAMENTE", siPendingIntent);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getActivity().getApplicationContext());
notificationManagerCompat.notify(NOTIFICACION_ID, builder.build());
}
}