How to launch other application and close it

Now I met one scene about the test,
I need to input the verification code from message app, but before that, I need to launch the Message app and then get the verification code, and then open my app and then input the code, how to make it happen in Appium, the doc doesn’t mention it.

Don’t do this via UI. Use API if you want your automated tests to be stable: https://rapidapi.com/blog/sms-apis-send-texts/