Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks not on Main Thread issue #9

Open
rotter opened this issue Apr 27, 2018 · 4 comments
Open

Callbacks not on Main Thread issue #9

rotter opened this issue Apr 27, 2018 · 4 comments

Comments

@rotter
Copy link

rotter commented Apr 27, 2018

I have integrated your plugin and it's working great - thanks!

But I have one problem/suggestion: make the callbacks run on main thread.

I was having a lot of problems until I found out the callbacks weren't on the main thread.

I had to turn on a flag on the callback and then check for the flag on the next Update. No big deal, but it would be better if the callback was already on the main thread, or at least make it clear for the developer that the callbacks are not on the main thread.

Best

@rotter
Copy link
Author

rotter commented Apr 27, 2018

Obs: I have just noticed that you do mention that the callbacks are not on (Unity's) main thread... but who reads documents? :)

Just kidding, but anyhow if you could somehow make it run on Unity's main thread it would be much better

@STARasGAMES
Copy link

I think you can do it by yourself.

public IEnumerator MyPermissionRequestCoroutine(string permission, Action grantedPermission, Action deniedPermission ){
                bool granted = false;
                bool gotCallback = false;
                AndroidPermissionsManager.RequestPermission(new string[] { permission }, 
new AndroidPermissionCallback(
                    grantedPermission =>
                    {
                        gotCallback = true;
                        granted = true;
                    },
                    deniedPermission =>
                    {
                        gotCallback = true;
                        granted = false;
                    }
                    ));

                while (gotCallback == false)
                    yield return null;
                if (granted)
                {
                    grantedPermission();
                }
                else
                {
                    deniedPermission();
                }
}
//and use
StartCoroutine(MyPermissionRequestCoroutine( ... ));

(written from head)

@rotter
Copy link
Author

rotter commented Apr 30, 2018

Thanks for the suggestion. I had already made a solution similar to this, using flags.

But anyway it would be best for the user of the plugin if the callback was already on the main thread, so he didnt need to do anything (or lose time with crashes not noticing the callback isn't on the main thread).

@DmitriyYukhanov
Copy link

Context synchronization should be used for this indeed.
But it's not as trivial as to use flags and async / coroutines.

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

No branches or pull requests

3 participants