I'm designing an android app that requires me to make the main Thread
sleeps for a certain amount of time, I know that this will make the app freeze and the UI will be not an editable material, BUT, that's what I need in my app and I'm fine with that, the problem is, when the user consequently hitting the UI while the main Thread
is sleeping, the app crashes and gives me the following Log
:
06-15 13:10:57.620: E/ActivityManager(542): ANR in com.example.myapp (com.example.myapp/.Login)
06-15 13:10:57.620: E/ActivityManager(542): PID: 1339
06-15 13:10:57.620: E/ActivityManager(542): Reason: Input dispatching timed out (Waiting because the touched window has not finished processing the input events that were previously delivered to it.)
06-15 13:10:57.620: E/ActivityManager(542): Load: 0.67 / 0.36 / 0.14
06-15 13:10:57.620: E/ActivityManager(542): CPU usage from 8638ms to 2834ms ago:
06-15 13:10:57.620: E/ActivityManager(542): 2.7% 112/mediaserver: 0.1% user + 2.5% kernel
06-15 13:10:57.620: E/ActivityManager(542): 1.2% 542/system_server: 0.6% user + 0.5% kernel / faults: 10 minor
06-15 13:10:57.620: E/ActivityManager(542): 1% 100/vinput: 0% user + 1% kernel
06-15 13:10:57.620: E/ActivityManager(542): 1% 1339/com.example.myapp: 0.8% user + 0.1% kernel / faults: 19 minor
06-15 13:10:57.620: E/ActivityManager(542): 0.5% 102/local_opengl: 0% user + 0.5% kernel
06-15 13:10:57.620: E/ActivityManager(542): 0.3% 109/surfaceflinger: 0.3% user + 0% kernel
06-15 13:10:57.620: E/ActivityManager(542): 0% 3/ksoftirqd/0: 0% user + 0% kernel
06-15 13:10:57.620: E/ActivityManager(542): 0.1% 56/adbd: 0% user + 0.1% kernel
06-15 13:10:57.620: E/ActivityManager(542): 0% 103/local_gps: 0% user + 0% kernel / faults: 4 minor
06-15 13:10:57.620: E/ActivityManager(542): 0.1% 598/com.android.systemui: 0.1% user + 0% kernel / faults: 1 minor
06-15 13:10:57.620: E/ActivityManager(542): 0% 697/com.android.inputmethod.latin: 0% user + 0% kernel / faults: 5 minor
06-15 13:10:57.620: E/ActivityManager(542): 4% TOTAL: 1.4% user + 2.5% kernel
06-15 13:10:57.620: E/ActivityManager(542): CPU usage from 696ms to 1199ms later:
06-15 13:10:57.620: E/ActivityManager(542): 1.7% 100/vinput: 0% user + 1.7% kernel
06-15 13:10:57.620: E/ActivityManager(542): 2% TOTAL: 2% user + 0% kernel
How can I preventing making my app ignore any user interactions while sleeping?
if it's worth to mention, I'm catching the InterruptedException
while making the Thread
sleeping:
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}