I have a Service running in the Background. It fetches some strings over IP.
It should truncate them and coordinate them to some variables.
So I thought:
public class Listener extends Service{
public void main(){
//fetch and preprocess data
data=fetched_string;
}
public String data=null;
public String getData(){return data;}
}
To my understanding, this should work. But how can I access this string data from another class or whats wrong with my Idea?
Or maybe there is a more elegant solution for android?
Provided your service is running when your application is running i.e. not being called up by a BroadcastReceiver in a different process, extend the Application class, shown here and have your service set them. Then the global variable can be accessed by other classes in your application. Otherwise, have the service write them into a Sqlite database and access them from there.