# How to leave a meeting or end Zoom SDK service programmatically

**URL:** <https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550>\
**Category:** Android\
**Created:** [January 26, 2021, 12:17am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550 "2021-01-26T00:17:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerger](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@gerger](https://devforum.zoom.us/u/gerger)\
**Post date:** [January 26, 2021, 12:17am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/1 "2021-01-26T00:17:14Z")

</div>

**Description**

For the Zoom Android SDK, custom UI, my custom activity extends the SDK’s MeetingActivity, in the @Override public void onBackPressed(), I want to leave the meeting and stop Zoom SDK service.

Currently I use the `onClickLeave();`, it will show a leave button in the meeting window, user can leave the meeting after clicking on the leave button. However, is there any way to leave the meeting directly without clicking the leave button?

I tried to just finish my custom activity, the meeting window is gone, though the Zoom SDK service is still running at the background, and I can’t join a new meeting because I didn’t leave the old meeting.

Please help, thanks a lot!

gerger

**Which version?**  
latest SDK version

---

<div class="post-metadata">

**Author:** ![egon](https://avatars.discourse-cdn.com/v4/letter/e/3ec8ea/32.png) [@egon](https://devforum.zoom.us/u/egon)\
**Post date:** [January 26, 2021, 12:38pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/2 "2021-01-26T12:38:26Z")

</div>

You call leaveCurrentMeeting. E.g. mMeetingService.leaveCurrentMeeting(end);

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [January 26, 2021, 6:23pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/3 "2021-01-26T18:23:19Z")

</div>

Hi @gerger, thanks for the post (and thanks to @egon for helping out!).

The method mentioned in the previous reply is correct. The API reference for this can be found [here](https://marketplacefront.zoom.us/sdk/meeting/android/us/zoom/sdk/InMeetingService.html#leaveCurrentMeeting-boolean-). Please don’t hesitate to reach back out if you encounter any issues while using this method.

Thanks!

---

<div class="post-metadata">

**Author:** ![nikhildfoe](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nikhildfoe/32/22119_2.png) [@nikhildfoe](https://devforum.zoom.us/u/nikhildfoe)\
**Post date:** [June 30, 2021, 7:08am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/4 "2021-06-30T07:08:19Z")

</div>

Hi @jon.zoom I tried using the following code for leaving a meeting.

**mZoomSDK.getMeetingService().leaveCurrentMeeting(true);**

It’s restarting my app. I’m using Android Zoom SDK. I couldn’t find the version number.  
Help me here please, so that it won’t restart the app.

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [June 30, 2021, 5:12pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/5 "2021-06-30T17:12:27Z")

</div>

Hi @nikhildfoe, thanks for using our SDK.

Sorry to hear you’re running into an issue with this. When you observe it “restarting” your app, that sounds like it is crashing and relaunching. Can you get the stack trace of the crash? Also, at what point are you calling this method?

Thanks!

---

<div class="post-metadata">

**Author:** ![nikhildfoe](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nikhildfoe/32/22119_2.png) [@nikhildfoe](https://devforum.zoom.us/u/nikhildfoe)\
**Post date:** [June 30, 2021, 6:10pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/6 "2021-06-30T18:10:20Z")

</div>

Thanks for replying @jon.zoom . I don’t think it’s a crash because if it is indeed that, why would it result in a relaunch of the app. And when I commented that particular code, the app didn’t “restart”. So, I figured it has got to do with something related to the leave meeting code.

Is there a meeting setting where we can turn on or off for this sort of behaviour?

Anyway, I’ll once again check the stack trace. Thanks.

BTW, I’m using this code to make the user leave meeting whenever from the host side it’s stopped or whenever the user wants to leave the current meeting.

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [June 30, 2021, 10:22pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/7 "2021-06-30T22:22:45Z")

</div>

Hi @nikhildfoe,

There is nothing within the Android SDK where we would intentionally “restart” an app. When an Android app crashes for the first time, the OS usually will re-launch the app immediately. Please let me know once you are able to provide the full stack trace of this crash so that we can investigate. 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![nikhildfoe](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nikhildfoe/32/22119_2.png) [@nikhildfoe](https://devforum.zoom.us/u/nikhildfoe)\
**Post date:** [July 1, 2021, 7:57am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/8 "2021-07-01T07:57:07Z")

</div>

Hi @jon.zoom, I looked for the stack trace and I couldn’t find anything related to this or the crash. Can I know if there is any other way to leave meeting other than this method?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![nikhildfoe](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nikhildfoe/32/22119_2.png) [@nikhildfoe](https://devforum.zoom.us/u/nikhildfoe)\
**Post date:** [July 1, 2021, 11:46am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/9 "2021-07-01T11:46:46Z")

</div>

Hi @jon.zoom , just found out why it was happening. It seems there’s a call back function onMeetingLeaveComplete() which will be called after successfully leaving a meeting. There was a finish activity code in that callback and then there was another service which will auto-launch our app whenever this particular activity gets destroyed this way.

Anyways, thanks for your help.

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [July 1, 2021, 7:43pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/10 "2021-07-01T19:43:19Z")

</div>

I’m glad to hear you were able to figure this out in your app!

---

<div class="post-metadata">

**Author:** ![shingshing6](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@shingshing6](https://devforum.zoom.us/u/shingshing6)\
**Post date:** [October 19, 2021, 3:33am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/11 "2021-10-19T03:33:37Z")

</div>

Hi @jon.zoom

I have encounter the same issue after called `leaveCurrentMeeting(false);`

> D/sensors\_hal( 1307): flushSendCmplt: handle=46  
> D/sensors\_hal\_Ctx( 1307): poll:polldata:1, sensor:0, type:0, x:0.000000 y:0.000000 z:12752584845336616345141232632070144.000000  
> D/sensors\_hal\_Util( 1307): waitForResponse: timeout=0  
> E/AndroidRuntime(31614): FATAL EXCEPTION: mqt\_native\_modules  
> E/AndroidRuntime(31614): Process: myapp, PID: 31614  
> E/AndroidRuntime(31614): java.lang.IllegalThreadStateException: onConfNativeMsg is not called from main thread  
> E/AndroidRuntime(31614): at com.zipow.videobox.s.b.f.a(ZmConfStateMgr.java:69)  
> E/AndroidRuntime(31614): at com.zipow.videobox.conference.jni.ZmConfDefaultCallback.onConfStatusChanged(ZmConfDefaultCallback.java:1)  
> E/AndroidRuntime(31614): at us.zoom.internal.jni.helper.ZoomMeetingSDKMeetingHelper.leaveOrEndMeetingImpl(Native Method)  
> E/AndroidRuntime(31614): at us.zoom.internal.jni.helper.ZoomMeetingSDKMeetingHelper.b(ZoomMeetingSDKMeetingHelper.java:2)  
> E/AndroidRuntime(31614): at us.zoom.internal.impl.f0.leaveCurrentMeeting(MeetingServiceImpl.java:11)  
> E/AndroidRuntime(31614): at myapp.MyMainActivity.leaveVideoConsultation(MyMainActivity.java:334)  
> E/AndroidRuntime(31614): at java.lang.reflect.Method.invoke(Native Method)  
> E/AndroidRuntime(31614): at java.lang.reflect.Method.invoke(Method.java:372)  
> E/AndroidRuntime(31614): at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)  
> E/AndroidRuntime(31614): at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)  
> E/AndroidRuntime(31614): at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)  
> E/AndroidRuntime(31614): at android.os.Handler.handleCallback(Handler.java:739)  
> E/AndroidRuntime(31614): at android.os.Handler.dispatchMessage(Handler.java:95)  
> E/AndroidRuntime(31614): at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)  
> E/AndroidRuntime(31614): at android.os.Looper.loop(Looper.java:135)  
> E/AndroidRuntime(31614): at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)  
> E/AndroidRuntime(31614): at java.lang.Thread.run(Thread.java:818)  
> D/LGImageQualityEnhancementService( 5748): activityResuming: myapp/myapp.MyMeetingActivity  
> D/LGImageQualityEnhancementService( 5748): handleCallbackActivity(), isEnhanced: false

Thanks

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [October 19, 2021, 11:12pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/12 "2021-10-19T23:12:46Z")

</div>

Hi @shingshing6,

Based on the error you are seeing, it appears that you are not calling `leaveCurrentMeeting` from the main thread. Please keep in mind that all SDK methods must be called from the main thread.

Thanks!

---

<div class="post-metadata">

**Author:** ![shingshing6](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@shingshing6](https://devforum.zoom.us/u/shingshing6)\
**Post date:** [October 20, 2021, 2:24am UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/13 "2021-10-20T02:24:10Z")

</div>

Hi @jon.zoom

Yup, but how can i ensure it is called from main thread? Or how to check if i am on the main thread or not?

When i call getMeetingStatus, it can return the current meeting status. Just call leaveCurrentMeeting will cause the error.

thanks

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [October 20, 2021, 6:20pm UTC](https://devforum.zoom.us/t/how-to-leave-a-meeting-or-end-zoom-sdk-service-programmatically/41550/14 "2021-10-20T18:20:48Z")

</div>

Hi @shingshing6,

Managing threads in your application is outside of the scope of what the SDK is responsible for, so I would recommend checking out the [official Android documentation](https://developer.android.com/guide/components/processes-and-threads) on the topic.

> When i call getMeetingStatus, it can return the current meeting status. Just call leaveCurrentMeeting will cause the error.

Not all SDK methods will cause a crash when called outside of the main thread, but all of them should be called on the main thread.

Thanks!
