Basically I have created an app into which the user enters a number (in seconds). They then click a button and a service is created which runs a countdown starting at the number of seconds entered. However in my service I reference variables such as:
public EditText text = (EditText)findViewById(R.id.editText1);
int Time = Integer.parseInt(text.getText().toString());
This ‘breaks’ the service as it is static and can’t reference findViewById.
I have tried for hours to work around this but I have no clue, any help much appreciated!
Why does the
Servicehave to bestatic? AServiceshould be either started/stopped or bound/unbound (or a combination of the two). You shouldn’t have to create astaticAndroidService.Put this code into your
Activityand not theService……then just pass the time to the
Servicein theIntentyou use to start it…Then in the
ServiceonStartCommand(...)method use…