Ask Your Question

RosActivity crashes when switching from SpeechRecognition Activity to RosActivity [closed]

asked 2015-11-12 01:52:29 -0500 gravatar image

Hi all,

I tried to wrote an Android app to use SpeechRecognition Activity to get a recognized string, and use rosjava/Android_core to publish the recognized string to a topic.

But the problem is, each time when it recognized speech and switch back from SpeechRecognition activity to RosActivity, the RosActivity crash. Can anyone help to check it? Thank you.

The code is here:

        mButton1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            // do something ....

            Intent intent = new Intent(
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.UK);

            try {
                startActivityForResult(intent, RESULT_SPEECH);
            } catch (ActivityNotFoundException a) {
                        "Speech not supported", Toast.LENGTH_SHORT).show();


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case RESULT_SPEECH:
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> matches = data

                if (matches.size() > 0) {
                    Log.d(TAG, matches.get(0));

                    String text = matches.get(0);
                    myPublisher.publishMessage(text);  // added by KKUEI

MyPublisher is here:

public class MyPublisher extends AbstractNodeMain {

private String topic_name = "MyPublisher/messages";
private Publisher<std_msgs.String> publisher;

public MyPublisher() {
    topic_name = "MyPublisher/messages";

public MyPublisher(String topic)
    topic_name = topic;
public GraphName getDefaultNodeName() {
    return GraphName.of("MyPublisher/publisher");

public void onStart(final ConnectedNode connectedNode) {

    publisher = connectedNode.newPublisher(topic_name, std_msgs.String._TYPE);


public void publishMessage(String s)    {
    std_msgs.String str = publisher.newMessage();
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2017-04-20 13:28:06.860077


Can you post the error log message?

mmore gravatar image mmore  ( 2016-02-26 00:58:17 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-10 18:26:55 -0500

ilmatematico gravatar image

the same for me, it seems that the finish is propagated somehow to parent activity. It's not crashing with error, but politely. As soon as onActivityResult contract the stack then mainactivity go to background.

edit flag offensive delete link more

Question Tools



Asked: 2015-11-12 01:52:29 -0500

Seen: 848 times

Last updated: Jan 10 '17