Android Emulator VS Real Device

Android Emulator vs Real Device

I am aware of these limitations:

  1. Pre-installed software. Real device can have preinstalled a lot more applications than emulator.
  2. You cannot use "capture" photo/video functions in emulator.

According to emulator documentation, its limitations are:

The functional limitations of the emulator include:

  • No support for placing or receiving actual phone calls. You can
    simulate phone calls (placed and received) through the emulator
    console, however.

  • No support for USB connections

  • No support for device-attached headphones
  • No support for determining network connected state
  • No support for determining battery charge level and AC charging state
  • No support for determining SD card insert/eject
  • No support for Bluetooth

IMO you can use emulator to simplify UI development, to view UI on "device screen", to be sure that app layout is ok, app can be run, you can test some special cases by simulating gps position, network speed or messaging etc. But testing on real device is a must.

Difference between running a program in Android emulator and physical device?

If you have a physical device, you can just use that. No need to run the emulator at all. An emulator is mostly used because it is convenient and easy to test different versions of android. For example, some libraries/UI component may behave differently on different phones.

It is better to use a physical device if your app is using radios like Bluetooth etc.

Layout looks different in Android emulator compared to real device

Add
android:layout_marginStart or android:layout_marginRight

and

android:layout_marginEnd or android:layout_marginLeft

to your ImageButtons like this:

<ImageButton
android:id="@+id/imageButton_1"
android:layout_width="0dp"
android:layout_height="128dp"
android:layout_marginTop="12dp"
android:layout_marginStart="10dp" // <==== Change to your margin
android:layout_marginEnd="10dp" // <==== Change to your margin
/>

Your full XML with margins: (Edited)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_mainActivity"
android:layout_width="match_parent"
android:layout_height="135dp"
android:background="#435cb53f"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@android:color/holo_green_light">

<TextView
android:id="@+id/textView_ToolBar_FoodSelectionActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="24sp"
android:text="Food" />
</android.support.v7.widget.Toolbar>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_layout"
android:layout_below="@+id/toolbar_mainActivity"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<View
android:id="@+id/imageButton_1"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="50"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/test" />

<View
android:id="@+id/imageButton_2"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="50"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/test" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<View
android:id="@+id/imageButton_3"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="50"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/test" />

<View
android:id="@+id/imageButton_4"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="50"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/test" />

</LinearLayout>

</LinearLayout>

</ScrollView>

<LinearLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#FFD600"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true">

<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:layout_weight="1"
android:background="@drawable/test"
android:text="A" />

<Button
android:layout_gravity="center_vertical"
android:id="@+id/button2"
android:layout_weight="1"
android:text="B"
android:layout_width="0dp"
android:layout_margin="4dp"
android:layout_height="wrap_content"/>

<Button
android:layout_gravity="center_vertical"
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_weight="1"
android:text="C"
android:layout_margin="4dp"
android:layout_height="wrap_content"/>

<Button
android:layout_gravity="center_vertical"
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_weight="1"
android:text="D"
android:layout_margin="4dp"
android:layout_height="wrap_content"/>

</LinearLayout>
</RelativeLayout>

Xml for @drawable/test

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp"/>
<solid android:color="#ffaa"/>
</shape>

The problem is solved by replacement ConstraintLayout with RelativeLayout and LinearLayout

How does Android emulator performance compare to real device performance?

Generally speaking, the emulator is much slower than a device at CPU and GPU tasks. That's for at least two reasons:

  1. The emulator is running ARM opcodes, converting them into equivalent x86 instructions, which is slow
  2. Devices (usually) have graphics accelerators, whereas the emulated environment does not, despite whatever video card you have on the machine running the emulator

To put things in perspective, I do my Android work on an Intel quad-core 2.66GHz with a fairly nice graphics card. For videos that work fine on devices, I can sometimes get them to play back in the emulator.

The emulator is faster than a device, though, at "disk" I/O. When you write to "flash" on the emulator, you are writing to a disk image file that probably resides on a regular hard drive, assuming you're not using an SSD. Actually writing to flash on a device can be massively slower -- Brad Fitzpatrick, at last week's Google I|O 2010 conference, cited spikes of up to 200ms to write a single byte to flash. And, the combination of Android, flash, and the yaffs2 filesystem apparently causes a device to get progressively slower at flash I/O as the flash fills up. Hence, his recommendation was to do any flash writes in a background thread instead of the main application thread, where it can tie up the UI and lead to a "janky" app.

(apparently, "janky" is a technical term... :-)

BTW, when it shows up online, definitely watch Brad's presentation on YouTube. It may be a bit difficult to follow at times, because he spoke very quickly, but it was full of useful tidbits related to performance.

What's the difference between real device and simulator/emulator?

Recently in QCon, Gerard Meszaros said that we should run automation tests only on simulators to improve efficiency.

This was odd advice, if that is really what Mr. Meszaros said. Running tests on the emulator is fine, but "only" is an excessive recommendation. There is no harm in running automated tests on devices, and you can learn a lot from doing so.

But I'm not sure if there will be some issues that can only found in a real device?

Of course.

  • Many devices have multi-core CPUs, whereas the emulator only emulates a single core at this time
  • Device storage tends to run a lot slower than does storage on the emulator
  • Device manufacturers tinker with Android in ways that will not appear on an emulator running stock Android
  • The emulator only loosely emulates hardware related to power, Internet (e.g., no mobile data, no WiFi), GPS, sensors, camera, etc.
  • The emulator does not support some device capabilities, like the new V2 version of Maps, the Play Store, multiple accounts on Android 4.2, etc.

And so on.

Or some components like camera, gravity sensors could not be tested in a simulator/emulator?

Those ones are difficult to test in an automated fashion, period.

Emulator vs Phone which one to rely on?

The emulator will always be slower than a real device (most likely, slower than any real device), so don't worry too much about it.

However, due to it's slowness, it can highlight areas where you may want to spend some time optimising your code that you may not necessarily find on your hardware. This is especially true on portable devices with limited CPU power, resources, and electrical power available.

It may be worth trying to find out what is causing the slowdowns in the emulator - if it's regular enough and accompanied by (for example) high CPU usage, then while a physical device may handle it better, you may find that you are unnecessarily consuming battery power and your users may not thank you for that.



Related Topics



Leave a reply



Submit