0

I have 2 fragments and one of them I'm trying to update some views after some data update. My views are updated fine when I remain in fragment when I have these views. After changed to another fragment my thread continues to work fine. But after I return for the first fragment my views can't be updated.

myThread = new Thread(){
        @Override
        public synchronized void run(){
            while( true ){
                try {
                    sleep( 2000 );
                    myActivity.runOnUiThread( new Runnable(){
                        @Override
                        public void run(){
                            updateViews();
                        }
                    });

                } catch ( InterruptedException e ) {
                    e.printStackTrace();
                }
            }
        }
    };

This is the update function:

private void updateViews(){
    textView.setText( _chronometerService.getTime() );
}

Notice my thread continues to update data, my issue is why views can't be updated.

learner
  • 1,311
  • 3
  • 18
  • 39

1 Answers1

0

Maybe you're creating a new fragment while switching?

Duke79
  • 827
  • 1
  • 10
  • 21