Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes Thread.sleep(n) in Android runs new thread?
    text
    copied!<p>I have a tricky question about threads on which I am unable to find answer. The thing is that I need to make dummy app, with splashscreen on for 2 sec, and after it, the new activity is started. The user can stop this waiting process by pressing back arrow and then splashscreen should be closed and second window should not be opened.</p> <p>What I came up with is <code>AsyncTakk</code> where in doInBackround is <code>Thread.sleep(2000)</code> and in <code>onPostExecute()</code> new app is opened. Also I have cancellation of this asynctask in <code>onPause</code>.</p> <p>So the doInBackground looks like that:</p> <pre><code>protected Boolean doInBackground(Void... voids) { try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } </code></pre> <p>I think that this is correct approach. According to <a href="http://developer.android.com/reference/java/lang/Thread.html#sleep%28long%29" rel="nofollow">documentation</a>:</p> <blockquote> <p>Causes the thread which sent this message to sleep for the given interval of time (given in milliseconds). The precision is not guaranteed - the Thread may sleep more or less than requested.</p> </blockquote> <p>For me it seems ok. </p> <p>However, I've got info from person checking it, that I'm starting new thread there and <strong>this is a mistake</strong>. </p> <p>I've added strict mode check in it and nothing. Checked also threads in eclipse, and also I don't see anything unusual.</p> <p>So, my question is - do I really make new thread and why, and if not, can you provide some links, to show him that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload