What is recommended way to update android ui from a -continuous- background thread?

后端 未结 2 1176

I\'ve read well enough on the subject to get well and thoroughly confused. I\'m doing a workout tracker app such as RunKeeper, which tracks how long and how far the user has

相关标签:
2条回答
  • 2020-12-20 09:11

    USe the following thread in AsyncTask... I hope this will work for you ....

       Handler mHandler;
    private final Runnable mRunnable = new Runnable() {
    
            public void run() {
                Call your AsyncTask Class;;;;
                mHandler.postDelayed(mRunnable, 1000);
            }
    
        };
    
    0 讨论(0)
  • 2020-12-20 09:12

    Use runOnUiThread().

    Define a Runnable:

    private Runnable mRunnable = new Runnable() {
        @Override
        public void run() {
            mTextViewOne.setText("10 miles!");
            mTextViewTwo.setText("40 minutes!");
        }
    };
    

    Inside your continuous thread:

    runOnUiThread(mRunnable);
    
    0 讨论(0)
提交回复
热议问题