0

Problem: I am attempting to display an image inside of an ImageView and then perform computation while this image is displayed. This is supposed to loop through multiple times.

Instead, the ImageView does not update until all computation is done, and LogCat displayed "Skipped xxxx amount of frames! The application may be doing too much work on its main thread."

Question: How do I force the thread to pause the computation such that it updates the ImageView and doesn't skip any frames?

Things I have tried:

`myImageView.setImageBitmap(myBitmap);`
`myImageView.invalidate();`
`myImageView.setVisibility(ImageView.INVISIBLE);`
`myImageView.setVisibility(ImageView.VISIBLE);`

Any help or guidance would be appreciated!

afathman
  • 5,993
  • 2
  • 20
  • 28
  • 1
    You really need to post more code than that such as where this code is located so we have a better understanding. Is it in a `loop`, another `Thread`, ...? Having some idea of what the "computation" is would likely be helpful, as well. – codeMagic Oct 22 '14 at 16:40
  • use imageview.post() to update the imageview – Elltz Oct 22 '14 at 16:42
  • 1
    Use AsyncTask for your long running work, and publishProgress() to update your UI while running. See http://stackoverflow.com/questions/25182211/updating-ui-during-asynctask and http://developer.android.com/reference/android/os/AsyncTask.html – CSmith Oct 22 '14 at 16:47

1 Answers1

1

Computation that takes more than 16ms has to be run in different thread than UI/main thread. You do not need to force to show image, you already do it right.

Volodymyr Lykhonis
  • 2,936
  • 2
  • 17
  • 13