GetInt can only be called from the main thread on Android

Hi,

I’m facing some problems recently with Android Build. I have a class to handle save locally, iCloud and Google Snapshot. It works like this:

public class DataCloudPrefs
{
        public static void SetInt(string key, int value)
    	{
    		#if CLOUDDATA_IMPLEMENTED
    
    			#if UNITY_IOS
    			iCloudBinding.setInt( value, key );
    			#elif UNITY_ANDROID
    			snapshotKeys.Add(key, value);
    			#endif
    
    		#endif
    
    		PlayerPrefs.SetInt(key, value);
    		PlayerPrefs.Save();
    	}

    public static int GetInt(string key)
	{
		#if CLOUDDATA_IMPLEMENTED

			#if UNITY_IOS
			return P31Prefs.getInt(key);
			#elif UNITY_ANDROID
			return int.Parse(snapshotKeys[key].ToString());
			#endif

		#endif

		return PlayerPrefs.GetInt(key);
	}
 }

So, I implemented a rewarded video on my game. On OnComplete function I call, for example:

GameController.Coins += 100;

which goes something like this:

public class GameController : MonoBehaviour
{
   private static int coins = 0;

   public static int Coins
   {
      get { return SaveController.Coins; }
      set 
      { 
           coins = value;
           SaveController.Coins = coins; 
      }
   }
}

public class SaveController : MonoBehaviour
    {
       public static int Coins
       {
          get { return DataCloudPrefs.GetInt("COINS"); }
          set { DataCloudPrefs.SetInt("COINS", value); }
       }
    }

This runs normally on Unity, on iOS, but on Android it returns me this error:

10-18 18:48:13.991: E/Unity(24084): GetInt can only be called from the main thread.
10-18 18:48:13.991: E/Unity(24084): UnityEngine.PlayerPrefs:GetInt(String, Int32)
10-18 18:48:13.991: E/Unity(24084): UnityEngine.PlayerPrefs:GetInt(String) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/PlayerPrefsBindings.gen.cs:49)
10-18 18:48:13.991: E/Unity(24084): DataCloudPrefs:GetInt(String) (at /Users/jota/GitHub/OvertimeStudios/CreepyBuster/Assets/Standards/Social Gaming Network/Cloud Data/DataCloudPrefs.cs:242)
10-18 18:48:14.251: I/Unity(24084): ArgumentException: GetInt can only be called from the main thread.
10-18 18:48:14.251: I/Unity(24084):   at UnityEngine.PlayerPrefs.GetInt (System.String key) [0x0000a] in /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/PlayerPrefsBindings.gen.cs:49 
10-18 18:48:14.251: I/Unity(24084):   at DataCloudPrefs.GetInt (System.String key) [0x00010] in /Users/jota/GitHub/OvertimeStudios/CreepyBuster/Assets/Standards/Social Gaming Network/Cloud Data/DataCloudPrefs.cs:242 

Why is this?

Solved: AdMob callbacks are not called on Unity main thread