Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Testing and securing android studio applications

You're reading from  Testing and securing android studio applications

Product type Book
Published in Aug 2014
Publisher Packt
ISBN-13 9781783988808
Pages 162 pages
Edition 1st Edition
Languages

Threads


The Threads tab displays the list of threads that are a part of the selected process. Applications have one main thread, also called as the UI thread, which dispatches the events to the user interface (UI) widgets. To perform long operations, it is necessary to create new threads so that the main thread is not blocked. If the main thread gets blocked, the whole UI will also get blocked.

To illustrate the working of this tool, run the following example. In Android Studio, create a new basic project with a main layout and a main activity. Add a button to the main layout named, for example, Start New Thread. Create a new method to be executed when the button is clicked and add the following code in the method:

public void startNewThread(View v){
  new Thread(new Runnable() {
    public void run() {
      Thread.currentThread().setName("My example Thread");
      
      try{
        Thread.sleep(30000);
      } catch (InterruptedException e){ 
        e.printStackTrace(); 
        }
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}