How to get the result from OnActivityResult inside another class?(outside of the activity

后端 未结 2 449
栀梦
栀梦 2021-01-22 11:25

I start the Voice recognition activity in a non activity class (by passing in the activity) here is the code:

private static void startVoiceRecognitionActivity(         


        
2条回答
  •  滥情空心
    2021-01-22 12:00

    I want to be able to get the result back inside the same class and not 
    in the activity.
    

    No can do, you really cant get the result without executing your activity because startActivityForResult is bounded with your activity when the other activity is finished.

    solution:

    Since you have your myActivity in your another class you can use the Intent from it to get the result from another activity in your class where you started the VoiceRecognition. Also make sure that you call it after the VoiceRecognition activity is finished.

    sample:

    myActivity.getIntent().getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    

提交回复
热议问题