I am trying to pass a String from my MainActivity to a non-activity class (A Notification Service) So that I can customise the notification message. I have tried using Intent however it won't work because it is a non-activity based class. What is the best why to do this?
I am currently trying to use a global variable but its not working.
MainActivity.java
private String var;
private String a = "Pumpkin";
public String getVar(){
return var;
}
public void setVar(String a){
var = a;
}
NotificationService.java
MainActivity b = ((MainActivity)getApplicationContext());
String var = b.getVar();
This crashes the app when even I call the variable var in NotificationService.java