Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Synchronous calls not working #1

Open
jzitkovic opened this issue Oct 8, 2017 · 2 comments
Open

Synchronous calls not working #1

jzitkovic opened this issue Oct 8, 2017 · 2 comments

Comments

@jzitkovic
Copy link

I have an issue with synchronous login when I call it from the main thread. I wanted to make my login synchronous because I use it in Rx chain and I don't want to have callbacks.

Response<ResponseZerokitLogin, ResponseZerokitError> r = Zerokit.getInstance().login(zerokitId, mPasswordET.getPasswordExporter(), true).execute();

Here is my log:

java.lang.IllegalStateException: Sync method call from the main thread is only possible after the initialization was finished.You can call sync method from background thread any time, or from main thread after the initialization is done. You can call async method from any looper thread any time
                                                                                at com.tresorit.zerokit.Zerokit$CallAction.checkThreadSync(Zerokit.java:1407)
                                                                                at com.tresorit.zerokit.Zerokit$CallAction.execute(Zerokit.java:1447)
                                                                                at de.gesundheitscloud.sdk.view.HCLoginActivity$1.onClick(HCLoginActivity.java:44)
                                                                                at android.view.View.performClick(View.java:4756)
                                                                                at android.view.View$PerformClick.run(View.java:19749)
                                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:135)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I have also tried to do initialize zerokit again with: Zerokit.getInstance().initMain(); but then I get ANR when I try to login.

@AngeliR
Copy link
Collaborator

AngeliR commented Oct 12, 2017

Hi,
The Zerokit.getInstance().initMain(); is not enough, because this call only returns a Call instance, so you need to call enqueue(new Action<Void>() {...} on it, because it is an async call.
The initMain() can only be called async, but after it has finished, you can call sync methods from main thread also. (From background thread you can call sync methods any time without the init restriction)

@jzitkovic
Copy link
Author

Yes, of course I have done that:

Zerokit.getInstance().initMain().enqueue(new Action<Void>() {
                    @Override
                    public void call(Void aVoid) {...}
                });

I have tested other methods like getIdentityTokens(String clientId).execute() synchronous and it worked.
But synchronous login Zerokit.getInstance().login(zerokitId, PasswordET.getPasswordExporter(), true).execute() method is not working. I always get ANR or this message: Sync method call from the main thread is only possible after the initialization was finished. You can call sync method from background thread any time, or from main thread after the initialization is done. You can call async method from any looper thread any time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants