Weird to me.... Simple App closing without reason at random time.

Hi all, I am new to android development and I have a weird behaviour but I just cant find any clue about it.

It should be something easy but for me I am in the dark.

I have a small app. It starts with the phone or by lcicing it, it shows the main Activity and then it starts a TimerTask that executes a class that extends from IntentService. So far its good.

In that IntentService, it has a while loop that iterates in this pseudo code


while (loop) {
    thread.sleep(2000);
    do something
    //saves a log, reads a file, sends it via sockets, receive a response and finish the loop
}

the code is being executed well, when it finds a file ina certain folder in the sdcard it processes it in the do something line, but… here is the problem

After certain time of use, the app just closes without generating any catchable exception. It may close after 1 hour of use or after 20 minutes or after 5 hours.

I have all my app surrounded by try and catch(Throwable) to log any error, but none is being thrown.

How can I achieve stability on a service like this one.

I have tried that approach and I face same problem. I guess android terminate apps when resources run low or apps running too long with minimal activity?
In the end I uses AlarmManager to do that periodic task instead.