I got an old MacBook Pro which only has two USB ports. I used an external keyboard and mouse. Both require USB ports. They left no room to connect a phone for debugging. Recently, I found there is a feature in visual studio. This new feature allows the developers to connect the devices via wifi. This measure can free up USB ports. Moreover, this method can do the debugging wireless, that is more convenient, I can carry the debugging device around and without wires, which can keep my desk cleaner.
Although it said that is wireless, you still need to connect with USB and open the device windows in the XCode. Then you need to check the box to enable wifi debug. After that, that is very easy. You select the device in Visual Studio when the device connected to the same wifi networks.
That is impossible to detect screen size in the Xamarin Form. You have to do in the native Android code.l suggest to do in MainActivity and then put in the static variable in the Forms PCL project like this:
Android.Util.DisplayMetrics displayMetrics = new Android.Util.DisplayMetrics();
Also, the unit of HeightRequest is device-independent units. But I found if you use HeightPixel divide by Density of the screen, then it will convert into the unit for HeightRequest or WidthRequest
If you want to use RequestLocationUpdates method in LocationManager, you need to add a class which implements ILocationListener to receive the callback from LocationManager. Most of the examples on the internet used the Activity as ILocationListener. That is easy if you choose the implementation in this way. But I wish to build a self-contained class which does not inherit any UI class.
locationManager.RequestLocationUpdates(LocationProviders.GPS, 10, 10, this);
Firstly, I just implemented all methods from the interface. Then I got an invalid casting exception. It is because LocationManager required the class is a sub-class of Java.lang.Object. In the native Android SDK, all classes are sub-class of Java.lang.Object, but we are using Xamarin, that is .Net, not Java. Thus we need to inherit our class to be a Java Object. After I make my class to be a sub-class of Java.lang.The object, I got an exception about the invalid handle. That is because ILocationListener has a property
public IntPtr Handle
I built a property to get from Application Context
Actually, Handle Property is in the Java.lang.Object. I do not need to build my own, I need to remove the section. Then it works.
I got an app to call api in my server for loading the data. This make sense to use asynchronous methods for loading the data. I don't want the whole UI is locked for waiting the data. But I found
It won't works. I found the reason is all Asynchronous methods are executed by a different thread. You have to call UI main thread to bind the data to UI.
After I installed Facebook SDK for Andorid. I found I cannot deploy my app in the debug anymore. I clicked the play button in Visual Studio, no compilation errors at all. Visual Studio is only freezed in "Deploying in [Phone Name]" for a little white. Then it stoped and gave out this error message,'Exception in thread "main"'. After I did a number of random search in Google, I found some people in the Xamarin Forum mentioned they need to increase the heap size to 1G after installing Facebook SDK. Finally, I increased the heap size to 1G in (Project Properties -> Android Options->Advanced-> Java Max Heap Size). Then it works!