Update android Textview continuously

前端 未结 4 1101
执笔经年
执笔经年 2021-01-22 12:27

I am working on an Android Application which have an one activity class and service class. In service, Continuous bulk data (1090 by

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-22 12:42

    Use handler beacuse A Handler allows communicating back with UI thread from other background thread.

    boolean handlerStop = false;
    
        void handleHandler(){
            Handler handler =new Handler();
            final Runnable r = new Runnable() {
                public void run() {
                    handler.postDelayed(this, 30000);
                    if(!handlerStop) {
                        updateTextView() //update your text with other thread like asyncronous thread
                    }
                }
            };
            handler.postDelayed(r, 0000);
        }
    
        @Override
        public void onResume() {
            super.onResume();
            handlerStop=false;
            handleHandler();
        }
    
        @Override
        public void onPause() {
            super.onPause();
            handlerStop=true;
            handleHandler();
        }
    
        @Override
        public void onStop() {
            super.onStop();
            handlerStop=true;
            handleHandler();
        }
    

提交回复
热议问题