I am using Firebase for sending push notification to my app and want to save some values to sharedpreferences. Its working perfectly when the app is foreground but it is not saving the values when the app is in background. My code looks like this:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e("Remotemessage",remoteMessage.toString());
String Heading = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
Map<String, String> data = remoteMessage.getData();
Log.e("Firebase notification ", " KEY1");
sessionManager=new SessionManager(this);
Log.e("Firebase notification ", " KEY"+data.get("click_action"));
Log.e("Firebase notification ", " KEY new"+data.get("key"));
int studentid= Integer.parseInt(data.get("student_id"));
Log.e("STUDENT ID",""+studentid);
if(studentid!=0)
{
sessionManager.saveStudentId(studentid);
}
}
but notification is showing both cases. How to solve this issue??