Skip to main content

Posts

Showing posts with the label thread

What is the difference between Services, Thread and an AsyncTask in Android?

Thread Example n ANDROID -- Timer Thread Example Non Runnable States in Multithreading - Different states while thread is in runnable states What is a thread in java ? How to write interfaces in java or Android? More on Android ? Service is like an Activity but has no interface. Probably if you want to fetch the weather for example you won’t create a blank activity for it, for this you will use a Service. A Thread is a Thread, probably you already know it from other part. You need to know that you cannot update UI from a Thread. You need to use a Handler for this, but read further. An AsyncTask is an intelligent Thread that is advised to be used. Intelligent as it can help with it’s methods, and there are two methods that run on UI thread, which is good to update UI components.

Non Runnable States in Multithreading - Different states while thread is in runnable states

See more basics of thread in java here : What is thread in java ? The different states while thread is in runnable states are given below : Sleeping States :   may be alive, but not running  may return to runnable state  stop running for an amount of time  Waiting for Notifications :   wait for notification from other   send to runnable after notified thread Blocked on I/O : after availability of resource sends to runnable Blocked for Joint Completion : waiting for completion of another thread Blocked for Lock Acquistion : Come to this state because of  waiting to acquire the lock of an object.

What is a thread in java ?

see more post : Non Runnable States in Multithreading - Different states while thread is in runnable states A thread is a lightweight process.While dealing with one thread called single thread and with more thread called multi thread . Main Thread :                       When a standalone application is running it is in main thread. What created inside is called   child thread . Life Cycle Of Thread or States Of Thread :                  New State:                         When it is created and is when the thread is not alive ie, before start( ).            Runnable (ready to run) State:                          After invoking start( ) it goes to runnable state.                 ...

Blinking TextView - Two Methods

METHOD 1 private void blink(){ final Handler handler = new Handler(); new Thread(new Runnable() { public void run() { int timeToBlink = 600; //in milissegunds try { Thread.sleep(timeToBlink); }catch (Exception e) { }handler.post(new Runnable() { public void run() { TextView txt = (TextView)findViewById(R.id.usage); if(txt.getVisibility() == View.VISIBLE) { txt.setVisibility(View.INVISIBLE); }else { txt.setVisibility(View.VISIBLE); } blink(); } }); } }).start(); } METHOD 2 T...