Android application not responding out of sleep mode.

My team and I are working on an alarm clock function on an Android device that, if necessary, tries to bring a device out of sleep mode, and sets off an alarm scene using a native Java plugin. But we’re facing a problem – it crashes about one in six times, due (we think) to a problem with the application taking too long to load on startup. The device tells us that the app is not responding after starting up. This means our code to start up the app is working. But it does this instead of starting the alarm, meaning that our alarm clock doesn’t work.

In DDMS we get an error citing ANR (application not responding) as the issue, and then a WIN DEATH (window death) comes after, which means that our activity was killed by the system, correct? We have since learned that this results from an application trying to do too much in its main thread. However, we don’t know:

  1. How to avoid this problem in Unity, by causing the main thread to do less work. The first scene the alarm clock opens is empty. The entire app is about 80.6 mb.

  2. Why this problem would occur when the alarm happens while the device is sleeping, but not at other times.

I’ve attached logs of what the device does when it’s successful and when it fails. Help me, Obi Wans! You’re my only hope! Our deadline is tomorrow. :frowning:

Here’s the FAIL log:

Here’s the SUCCESS log:

You are correct that Android will kill your app if it is running too long on the UI thread, but I don’t think that’s your issue, unless it was further down in the log, but I stopped reading at line 109 where it reported a null reference exception. Make sure you are catching that. Otherwise, it looks like you’re loading up some json/database type stuff that can be slow, so be sure to run all of that in either an Intent Service or Async Thread. Intent service is the easiest to work with. Also, alarm clock apps that require a game to shut off the alarm is patented, so just be careful. :slight_smile: