-2

I am developing an App that uses NFC.

When a new intent is discovered (NFC), the Activity goes to onStop state, then it executes onNewIntent code which executes a new Thread, in the middle of the Thread execution, the main Activity goes to onResume state, and then the thread keeps on with its execution.

Is there a way to control this sequence, I mean: Is there a way to execute onResume before the Thread, or at least to be sure that onResume is going to be executed before the Thread have finished?

EDIT:


To solve the issue, I put the Thread in sleep mode during 2000 milliseconds, this way the main activity takes the control and executes onResume, but this sounds like dirty workaround.

This way another problems came out, during those 2000 milliseconds, a new intent could be discovered, executing another Thread.

Thanks

Jachu
  • 405
  • 5
  • 10

1 Answers1

1

When your thread completes, it could enqueue something (a Runnable, perhaps) to a queue. In onResume() you could then look in the queue and if there is anything there you could run it.

David Wasser
  • 93,459
  • 16
  • 209
  • 274