小编Tom*_*Tom的帖子

我如何使Android应用程序每隔X秒执行一次操作

你好,我想做每1秒呼叫功能或做其他事情的apliacation.我有这个代码不工作你能说出什么问题吗?

public class App5_Thread extends Activity implements Runnable {    
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                Thread thread = new Thread(this);    
                thread.start();
        }
        @Override                    
        public void run() {                
                TextView tv1 = (TextView) findViewById(R.id.tv);
                showTime(tv1);                                                                
                try {
                    Thread.sleep(1000);
                }catch (Exception e) {
                    tv1.setText(e.toString());
                }            
        } 
        public void showTime(TextView tv1 ){                
            String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
            tv1.setText(sdf.format(cal.getTime())+" "+System.currentTimeMillis());                    
        }           
Run Code Online (Sandbox Code Playgroud)

}

multithreading android action

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

action ×1

android ×1

multithreading ×1