My application turned black screen right after I initialize service in my activity. No error or warning message was shown. Awhile later the application is already not responding and even after the time limit the service did not update info to the server. I wanted to use the service to send user’s location constantly to the server after every minute. Service is initialize in my activity. I also included the service in AndroidManifest.xml as well.
LocationService
The code below is my structure of Service
public class LocationService extends Service{
@Override
public IBinder onBind(Intent arg0){
return null;
}
private String TAG = "LocationService";
@Override
public void onCreate(){
super.onCreate();
boolean isUpdateResult = true;
try{
while(isUpdateResult){
new CountDownTimer (60000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
//Send information to server
}.start();
}
}
finally{
}
}
@Override
public void onDestroy(){
super.onDestroy();
}
}
Below is how I call the service in my main activity.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_screen);
startService(new Intent(Web_Slider.this,
LocationService.class));
}
Any idea what causes the black screen? Did I missed out something here?
Any comments will be appreciated! Thank you in advance.
I managed to solve this. Apparently if I run
new CountDownTimer (60000, 1000)in the beginning of the loop, the screen will turned into black screen. If not mistaken is due constantly create new CountDownTimer cause it unable to function as it should. The right way to put it is take away the While(isUpdateResult). The function will constantly start a count down timer because there is a .start(); after onFinish();. So there while loop is not needed.