How to create GraphicsDevice directly in Android?

Sometimes I waint create GraphicsDevice directly, in windows, it very simple,
GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters);
but in android, it became complexity, GraphicsAdapter is sealed class and the property
public DisplayMode CurrentDisplayMode { get {
View view = ((AndroidGameWindow)Game.Instance.Window).GameView;
return new DisplayMode(view.Width, view.Height, SurfaceFormat.Color);
}}
makes this question more difficult, how can i new GraphicsDevice in android?

You can probably create an interface that defines some kind of factory object that creates GraphicsDevice objects for you. Then you can implement that interface one way for Android and another way for Windows. Have your game’s constructor take an instance of your interface and then, when each platform creates its game, have it pass the appropriate instance down.

Now your game can simply call the CreateGraphicsDevice method on the interface and it will use whichever implementation it was given to create the new graphics device.

Hopefully that makes sense. Let me know if you have any questions :slight_smile:

this is not coding structure question, for example, i want create GraphicsDevice in Xamarin.Android projects, but when i execute
GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters); it
will throw System.NullReferenceException

Oh I see, my apologies for the misunderstanding :slight_smile:

That I’m not sure about. I’ve never tried to create a graphics device manually, only use the one that is provided by the Game class. I did some googling and this apparently a common issue that used to work, but changed somewhere along the way in MonoGame.

It might not be something that’s possible with the current framework? The source is on github, to learn more you might have to go digging through the code to understand how this object is created.