今天就跟大家聊聊有关详解Android 开发中的线程,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
Android 开发中线程的分析
代码:
package sw.angel.thread; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.util.Log; public class ThreadDemo extends Activity { private static final String TAG = "ThreadDemo"; private int count = 0; private Handler mHandler = new Handler(); private Runnable mRunnable = new Runnable() { public void run() { //为了方便 查看,我们用Log打印出来 Log.e(TAG, Thread.currentThread().getName() + " " +count); count++; setTitle("" +count); //每2秒执行一次 mHandler.postDelayed(mRunnable, 2000); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //通过Handler启动线程 mHandler.post(mRunnable); } protected void onDestroy() { //将线程销毁掉 //mHandler.removeCallbacks(mRunnable); super.onDestroy(); } }
网站题目:详解Android开发中的线程-创新互联
URL分享:https://www.cdcxhl.com/article18/cdoddp.html
成都网站建设公司_创新互联,为您提供移动网站建设、Google、网站策划、虚拟主机、定制网站、ChatGPT
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联