Simple Publisher and Subscriber for rosjava

asked 2015-09-14 17:44:25 -0500

idkm23 gravatar image

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>() {
        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.

edit retag flag offensive close merge delete