Robotics StackExchange | Archived questions

RosActivity crashes when switching from SpeechRecognition Activity to RosActivity

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:

https://github.com/wennycooper/Andbot_Speech/blob/master/app/src/main/java/com/example/kkuei/andbot_speech/MainActivity.java

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

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

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

and

@Override
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
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                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;
}
@Override
public GraphName getDefaultNodeName() {
    return GraphName.of("MyPublisher/publisher");
}

@Override
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();
    str.setData(s);
    publisher.publish(str);
}
}

Asked by kevin.kuei.0321@gmail.com on 2015-11-12 02:52:29 UTC

Comments

Can you post the error log message?

Asked by mmore on 2016-02-26 01:58:17 UTC

Answers

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.

Asked by ilmatematico on 2017-01-10 19:26:55 UTC

Comments