Friday, 23 August 2013

Home and Back buttons press: effect not immediate

Home and Back buttons press: effect not immediate

I introduced a Thread.sleep in different points of an Android application.
The objective is to give me enough time to press either Home or Back at
these exact points in code.
When I press one of these buttons at the sleep instruction, the button
action is not carried immediately and in some cases additional
instructions of the client application are executed. That is, the thread
is sleeping, I press Home, and the client application still processes a
few lines of code (after the sleep) before returning to the Home screen.
Why does this happen?
..
To give a more clear picture of the problem, consider the following block
of code:
instruction 1;
instruction 2;
instruction 3;
Thread.sleep(8000);
instruction 4;
instruction 5;
instruction 6;
instruction 7;
...
instruction N;
Home or Back are pressed at the sleep, but the application might still
execute a couple of instructions, say up to 6 or 7, before actually
terminating.
[edit] I want to add that the application includes several AsyncTasks, and
that I introduced sleeps both inside and outside of them.

No comments:

Post a Comment