There are two ways to use thread class.
One is directly used in the Thread.
new Thread(new Runnable() { @Override public void run() { //Do things. } }).start();
Another way is create a new class extend the Runnable interface, and implement the run() function.
public class MyClass extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Handler mHandler = new Handler(Looper.getMainLooper());
// Do it after 300 ms.
mHandler.postDelayed(DoThings, 300);
// Or do it right away.
//mHandler.post(DoThings);
}
private Runnable DoThings = new Runnable()
{
public void run()
{
// Do things.
}
};
}
java programming example codes
ReplyDeletejava simple code Example XML server