ayltai / Android-Lib-reCAPTCHA

[Deprecated] The reCAPTCHA Android Library provides a simple way to show a CAPTCHA as an ImageView in your Android app, helping you stop bots from abusing it. The library wraps the reCAPTCHA API.
Apache License 2.0
71 stars 27 forks source link

showChallenge() method throws NetworkOnMainThreadException #5

Closed sanusi87 closed 8 years ago

sanusi87 commented 8 years ago

I tried to reload the captcha once a user entered a wrong answer, I use this code:

ReCaptcha reCaptcha = (ReCaptcha)findViewById(R.id.recaptcha);
reCaptcha.showChallenge(SITE_KEY);

then it throws NetworkOnMainThreadException. I tried running it inside AsyncTask, then an error notice appears saying that showChallenge() must be called from the UI thread, currently inferred thread is worker...

any suggestion?

ayltai commented 8 years ago

In your case you need to use showChallengeAsync. Try invoking showChallengeAsync on your UI thread.

For historical reason, showChallenge is synchronous and it touches UI components so it is only intended for use in SDKs prior to Honeycomb.

ayltai commented 8 years ago

This issue is resolved in version 2.0.0.