Rof*_*ion 86
这是一个很好的教程:
http://android-developers.blogspot.de/2009/05/painless-threading.html
或者这是UI线程:
http://developer.android.com/guide/faq/commontasks.html#threading
或者这里是一个非常实用的:
http://www.androidacademy.com/1-tutorials/43-hands-on/115-threading-with-android-part1
另一个关于procceses和线程
http://developer.android.com/guide/components/processes-and-threads.html
小智 10
Androids强大的功能之一是AsyncTask类.
要使用它,您必须首先扩展它并覆盖doInBackground(...).
doInBackground在工作线程自动执行,并且可以在UI线程添加一些听众收到通知的状态更新,这些功能被称为:onPreExecute(),onPostExecute()和onProgressUpdate()
你可以在这里找到一个例子.
有关其他选择,请参阅以下帖子:
Handler vs AsyncTask vs Thread
这是Android的简单线程示例.这是非常基本的,但它应该帮助你获得一个观点.
Android代码 - Main.java
package test12.tt;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Test12Activity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView txt1 = (TextView) findViewById(R.id.sm);
new Thread(new Runnable() {
public void run(){
txt1.setText("Thread!!");
}
}).start();
}
}
Run Code Online (Sandbox Code Playgroud)
Android应用程序xml - main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id = "@+id/sm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
216931 次 |
| 最近记录: |