Ask Your Question
0

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

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

kevin.kuei.0321@gmail.com 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:

https://github.com/wennycooper/Andbot...

        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);
}
}
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

Comments

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
0

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

2 followers

Stats

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

Seen: 854 times

Last updated: Jan 10 '17