Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android emulator not showing canvas drawing

I have an app that draws animations to the canvas using a SurfaceView subclass. After upgrading to Android Studio 3.0, I started having problems with running the app on the emulator. The app works fine on a real Android device, but the drawing commands are not showing up at all when I run it on the emulator. There are buttons on the activity that show up, but the canvas is just blank and white. I tried the debugging technique here and it all looks fine when I inspect the bitmap, but it just won't show up at all on the emulator. Any ideas on how to resolve this would be fantastic.

like image 252
Kelsey Brennan Avatar asked Nov 12 '17 21:11

Kelsey Brennan


People also ask

How do I fix Android Emulator not working?

If the emulator fails to launch due to the error vulkan-1. dll cannot be found , you probably need to update the emulator. To update the emulator in Android Studio, go to Tools > SDK Manager and install the latest stable version of Android platform.

Can we draw directly on canvas in android studio?

There are many different things you can draw onto a Canvas . One of the most common drawing operations is to draw a bitmap (image) onto the canvas. The method for doing this is just called drawBitmap and it takes in the bitmap object that is loaded up either with Android's built-in mechanisms, or with Glide.

What is canvas drawing in Android?

Canvas API is a drawing framework that is provided in Android, with the help of which we can create custom shapes like rectangle, circle, and many more in our UI design. With the help of this API, we can draw any type of shape for our app. The drawing of the different shapes is done using Bitmap.

How do I pin an emulator to my screen?

Just press the 'window' button and the left arrow and the highlighted window will stack to the left. Press the 'window' button and the right arrow and the highlighted window will stack to the right. So you can stack eclipse on one side and emulator on the other.


2 Answers

I was having a hard time making canvas work in my app, and then I eventually thought it may be the emulator. Hans is right, you can make the canvases show up by tweaking the emulator settings.

Here's the settings that works for me on macOS 10.13.6 (any other combination didn't work):

  • OpenGL ES renderer: Desktop native OpenGL
  • OpenGL ES API level: Comptability (OpenGL ES 1.1/2.0)

Note that these fields are in the "Advanced" tabs under Settings.

Also, make sure to restart the emulator after updating the settings.

like image 101
jmlacroix Avatar answered Nov 01 '22 15:11

jmlacroix


Here is what worked for me: In the emulator click on the three dots at the bottom right (=More). Go to Settings and change the OpenGL ES renderer to Desktop native OpenGL.

like image 6
Hans Avatar answered Nov 01 '22 14:11

Hans