How can I run my code without launching the app?

I know this a noob question, but how can I run some code in my MainActivity.kt and not have to launch the app in the emulator?

All the run options I find in the IDE launch the emulator and searching the question doesn't help (I think I am asking it wrong).

If it helps, I'm just trying to perform an API call and explore the data so that's why I don't want to launch the app.

Posted Mar 21, 2021, 5:13 PM UTC

36
faresdev•

you need to make a service in background to handle api calls, but you still need to launch the app so you can launch service there for i think you can't get this code to work because it's not called yet

1
Useful_LimitOP•

I'm really new to this so I'm a bit confused by what you are saying. I just want to test the API call to make sure I get the data I think I am getting. Do I really need to run the emulator just to perform a simple API call?

1
Atheosomg•

I usually use Insomnia to do api calls if I want to test them out and see content outside app /before implementing it to app Google Insomnia Rest another similar program is postman

1
chazzcoin•

I use a program called Postman to make specific API calls that are separate from the app itself needing to do anything.

Postman allows you to setup headers, body, etc...works with XML and JSON.

Otherwise, idk of a way inside Android studio to do what you want without running the app.

1
GenderNeutralBot•

Hello. In order to promote inclusivity and reduce gender bias, please consider using gender-neutral language in the future.

Instead of postman, use mail carrier, letter carrier or postal worker.

Thank you very much.

^(I am a bot. Downvote to remove this comment. For more information on gender-neutral language, please do a web search for "Nonsexist Writing.")

1
AntiObnoxiousBot•

Hey u/GenderNeutralBot

I want to let you know that you are being very obnoxious and everyone is annoyed by your presence.

^(I am a bot. Downvotes won't remove this comment. If you want more information on gender-neutral language, just know that nobody associates the "corrected" language with sexism.)

^(People who get offended by the pettiest things will only alienate themselves.)

1