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

idkm23's profile - activity

2015-11-26 12:15:49 -0500 received badge  Famous Question (source)
2015-09-25 03:24:03 -0500 received badge  Notable Question (source)
2015-09-15 12:38:07 -0500 received badge  Popular Question (source)
2015-09-14 20:03:09 -0500 asked a question Simple Publisher and Subscriber for rosjava

I am working on an android application that will subscribe to a topic. When a message is received, I would like to display the message in a TextView. In my RosActivity's onCreate function I made a simple timer to periodically update the TextView:

    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {

            runOnUiThread(new Runnable() {

                public void run() {
                    //accesses a public static String variable from the 
                    //Listener class
                    myAwesomeTextView.setText( Listener.msg );
                }
            });
        }
    }, 100, 1000);

While in Listener, a subclass of AbstractNodeMain, I have a simple callback function that stores the result in the very same msg static variable

subscriber.addMessageListener(new MessageListener<std_msgs.String>() {
        @Override
        public void onNewMessage(std_msgs.String message) {
            msg = message.getData();
        }
    });

Interestingly enough, the program will read and display messages received over the topic, but only when the program initially loads.