I’ve created a class that extends Application.
This class starts a service when the application is loaded.
This service is running a thread in a loop, and need to update the application global variable throw the getter\setter method in this class:
public class AppLoader extends Application {
private boolean isInternetOn, isGpsOn, isThereActivityRunning;
private String results;
public String getResults() {
return results;
}
public void setResults(String results) { }
public boolean getIsInternetOn() {
return isInternetOn;
}
public void setIsInternetOn(boolean state) {
this.isInternetOn = state;
}
public boolean getIsGpsOn() {
return isGpsOn;
}
public void setIsGpsOn(boolean state) {
this.isGpsOn = state;
}
public void onCreate() {
super.onCreate();
final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, ServerConnection.class);
startService(intent);
Log.d("ServiceStart", "ServerConnection.java Service has been started");
}
}
I want to use the getter setter methods inside the thread and I couldn’t understand how to do it.
Help will be appreciated.
You need to have a Handler that you can send messages to. This is a very easy way to communicate across threads.