2

I want to test if my Looper finished its work because I want to execute code after all elements of my activity are on screen. I want to trigger an event after Looper finishes its work. Can I do that or is there any another way to execute my code after all elements in the UI appears on screen?

mjk
  • 2,443
  • 4
  • 33
  • 33

2 Answers2

1

Once you started a looper by calling Looper.loop() it does not exit until you explicitly call Looper.quit().

You can use Semaphore to coordinate your code, so you can wait until the Looper finish its work.

1- define a Semaphore object in your class and initialize it with 0 permits, e.g.

Semaphore semaphore = new Semaphore(0);

2- In the place where you want to wait call semaphore.acquire(), which will block until a permit is available

3- After you finish your looper call semaphore.release(), which will add a permit to the semaphore and the other waiting code will continue to run.

Note, that if the looper finished before semaphore.acquire() is called; it will continue immediately and will not block

See my answer here, for a code example on using Semaphore

Community
  • 1
  • 1
iTech
  • 18,192
  • 4
  • 57
  • 80
0

You can check the visibility of your elements. If they're true,run your code.... (Hope I understood right.)

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
Eveli
  • 498
  • 1
  • 6
  • 27
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Roman C Feb 07 '13 at 15:25
  • sure this is an answer... it says him a possibility to check his elements.. where is your prob??? – Eveli Feb 07 '13 at 15:31