ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Writing an image listener on android device; need debugging tips (why running out of memory?)

asked 2012-04-05 16:18:37 -0500

amigo gravatar image

updated 2012-04-06 06:32:19 -0500

I'm trying to write an app that can receive sensor_msgs/Image messages on an android device. I've modelled the code after android_tutorial_pubsub:

import org.ros.address.InetAddressFactory;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeMainExecutor;

import android.os.Bundle;

public class MainActivity extends RosActivity {
        private RosImageView<sensor_msgs.image> rosImageView;

        public MainActivity() {
                super("Android App", "Android App");

        protected void onCreate(Bundle savedInstanceState) {
                rosImageView = (RosImageView<sensor_msgs.image>)findViewById(;
                rosImageView.setMessageToBitmapCallable(new BitmapFromImage());

        protected void init(NodeMainExecutor nodeMainExecutor) {
                NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostName());
                nodeMainExecutor.execute(rosImageView, nodeConfiguration.setNodeName("myapp/image_listener"));

        protected void onDestroy() {

I am able to connect to the ROS master just fine:

~$ rosnode list

It is properly subscribed:

~$ rostopic info /camera/rgb/image_color 
Type: sensor_msgs/Image

Publishers: None

 * /myapp/image_listener (

When I use rosbag play on a bag file, it shows the publisher:

~$ rostopic info /camera/rgb/image_color 
Type: sensor_msgs/Image

 * /play_1333677784320867515 (

 * /myapp/image_listener (

But that's the end of good behavior. The image does not appear in the image view. Here is my res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:src="@drawable/ic_launcher" />


Before I start rosbag play, I am able to exit the app and re-enter no problem. Once the publishing starts, the app is pretty much frozen.

roswtf doesn't tell me anything interesting (I ran rosbag a second time, so the play node number is different).

~/ros_workspace/android_core/android_image_listener$ roswtf
Loaded plugin tf.tfwtf
No package or stack in context
Static checks summary:

No errors or warnings
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:

Found 2 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING Node [/myapp/image_listener] is not connected to anything
WARNING The following nodes are unexpectedly connected:
 * /play_1333678178991195080->/rosout (/rosout)
 * unknown (>/rosout (/rosout)

logcat gives me a bunch of (nonstop):

D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms
D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms
D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms
D/dalvikvm( 3678): GC_CONCURRENT freed 2048K, 25% free 34961K/46599K, paused 2ms+4ms

and I can get in logcat (after running rosbag a few times):

E/dalvikvm-heap( 3678): Out of memory on ...
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-04-06 10:35:00 -0500

damonkohler gravatar image

Please file an issue and attach a sample bag file that will cause the error. I'll try to reproduce it:

edit flag offensive delete link more

answered 2014-12-15 11:17:36 -0500

r2doesinc gravatar image

Perhaps try the CompressedImage message type. I have been using this type with no issues.

edit flag offensive delete link more

answered 2012-04-05 21:56:56 -0500

Lorenz gravatar image

The exception is caused by message deserialization. Android devices have a very limited amount of memory so I guess the image that you are transmitting is just too big. Try with a smaller image, maybe you need to write something like an image downsampling node.

edit flag offensive delete link more


I actually got the same code to work using the same bag file a few days ago before I got the latest rosjava_core and android_core. I just downgraded rosjava_core and android_core and verified again that it does work on the older versions. So I don't think it's the image size.

amigo gravatar image amigo  ( 2012-04-06 05:50:32 -0500 )edit

Question Tools

1 follower


Asked: 2012-04-05 16:18:37 -0500

Seen: 2,588 times

Last updated: Dec 15 '14