When the activity is destroyed, make sure any background thread is cancelled.

There was a race condition when the activity was destroyed when the background
thread was still running.
Before we release the handler, cancel any running thread, wait for it to
actually exit before purging the handler.
This code should be rewritten to use AsyncTask instead of raw threads
in my opinion.

Tested: I tried to import +100 vcard and make the app exit and it did not crash
however the current bug will show under high load. Need to wait for a monkey run
to confirm it is fixed.

Bug:2517391

Change-Id: I37e7619f6b93a8faa7da4506caffb9ed40e4f844
1 file changed