扩展Thread的示例代码:
public class CommonTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new Thread(){ public void run(){ System.out.println("Thread is running."); } }.start(); } }
使用Runnable的示例代码:
public class CommonTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new Thread(r).start(); } Runnable r = new Runnable() { @Override public void run() { System.out.println("Runnable running "); } }; }