0

I previously start speech recognition service from MainActivity by startActivityForResult and put onActivityResult also in the main. I also stop the service by finishActivity in the MainActivity. All work O.K.

Now I pass the active of the service to the Fragment and also the onActivityResult in the Fragment. It get there the replay. But when i put the finishActivity in the Fragment it mark it in red and didn't recognize it.

It is look it need activity so I add before getActivity.finishActivity(THE REQUEST CODE) and it run. But it is look that it doesn't close the service any more. Where could be the problem? Bar.

Emil
  • 2,786
  • 20
  • 24

2 Answers2

0

Try using this.stopSelf() if in the same service

Or inside your onActivityResult try calling stopService(intent)

Refer

alternative to finish() method for Service class? To kill it dead

for the same

Community
  • 1
  • 1
kuldeep
  • 817
  • 10
  • 27
0

See startActivityForResult() from a Fragment and finishing child Activity, doesn't call onActivityResult() in Fragment. The problem is the fragment's startActivityForResult() is remapping your request code, but the getActivity().finishActivity() is not mapping back. You need to start the activity from MainActivity instead of the fragment.

Sam
  • 40,644
  • 36
  • 176
  • 219