Super-charge your Android Developer Workflow with Chat-GPT 🚀

Take advantage of AI, and boost your productivity!

The Android Developer
7 min readJun 3, 2023

Introduction — An eye-opening experiment 👁

Hey everyone 👋, hope you’re doing well! For the past few weeks, I’ve been trying to incorporate Chat-GPT (I used Bing Chat because it uses GPT-4 under the hood and is free to use) into my daily Android Development workflow, trying to see if I’d be able to be more productive. And, it has been an extremely eye-opening experiment for me!

After using it for a few days, I was blown away by how much it accelerated my development workflow 🤯! I was able to do things much, MUCH quicker! Since I’ve been trying it out for a while now, I have a good idea of some prime use cases where Chat-GPT could be a great time saver in your development workflow. So, I’ll be sharing those in this article.

Note: I’ll be using Chat-GPT as an alias for Bing chat throughout this article because they are essentially the same.

A note to new Android Developers 👩‍💻

If you’re a new Android Developer, first and foremost, this article is not for you. This article is meant more for intermediate and advanced Android developers.

Secondly, do not use LLMs (Large Language Models) like Chat-GPT to just copy-paste code without understanding what the code does. Understanding Android development is a much more valuable skill than just copy-pasting code. Many don’t realize this, but, once you get a good understanding of all the fundamentals of Android Development, you’d actually be able to take even more advantage of LLMs in a manner, that will super-boost your productivity.

Extremely useful use cases for Chat-GPT that can super-charge your Android Developer workflow 🚀

Generating Docs 📑

Let’s start with a very simple use case. Writing docs is one of the most important things you’ll be doing as a developer. It not only helps others understand what your code does, but it helps you to remind yourself about what action the code you've written is performing when you come back and revisit it after a long time.

Traditionally it has been the bane of many programmers because it takes valuable time away from actually coding the thing you’re trying to build. Here, Chat-GPT can save tons of time! Just ask it to generate the docs for you. But, make sure to proofread and modify the documentation that it generated, if it doesn’t convey what you had in your mind. This is a super useful use-case and it saved tons of time for me! Here’s an example

// The function which needs to be documented
suspend fun getPlacesSuggestionsForQuery(
@Query("q") query: String,
@Query("session_token") sessionToken: String,
@Query("limit") @IntRange(1, 10) limit: Int = 10
): Response<SuggestionsResponse>

Prompt : Generate KDOC kotlin documentation for the following method — “..”

Generated documentation for the code snippet above

As you can see, it pretty much nailed the documentation. Just needs some minor tweaks. Imagine the amount of time that would’ve been wasted if I were to write this all by myself! Phew!

Generating mapper functions 📍

Here’s a simple, but very VERY useful use case. If you’ve written your apps by applying some clean-architecture principles, you would’ve probably written a lot of mapper functions. These are, for the most part, boilerplate code, that you must write, in order to convert objects used in one architectural layer, to objects used in a different architectural layer.

Again, Chat-GPT can make the work of writing all these mapper functions a breeze! Just add the definition of the two classes and ask it to write a mapper function. It’s that easy! Just make sure to verify that the code that it generated is correct. Here’s an example.

// Class 1
data class WeatherDetails(
val nameOfLocation: String,
val temperature: Temperature,
val wind: Wind,
val weatherCondition: WeatherCondition,
val humidity: String,
val pressure: String
) {
data class Temperature(
val currentTemp: String,
val minTemperature: String,
val maxTemperature: String,
)

data class Wind(val speed: String, val direction: String)

data class WeatherCondition(
val oneWordDescription: String,
@DrawableRes val currentWeatherConditionIcon: Int,
)
}

// Class 2
data class BriefWeatherDetails(
val nameOfLocation: String,
val currentTemperature: String,
val shortDescription: String,
@DrawableRes val shortDescriptionIcon: Int,
)

Prompt : Write a mapper function for the following two classes — “…” and “…”

The Generated Mapper function for the two classes

But, I wanted the mapper function to be an extension of the WeatherDetails class. So, I asked it to make it as an extension function.

Prompt : Make it as an extension function of the WeatherDetails class

The response to the above prompt asking it to make it as an extension function

And, it did exactly, what I wanted it to do! And, it even changed the name of the method to a more meaningful name! How cool is that!

Fill data classes with sample data ✍️

As a developer, you would've definitely been in a situation where you needed to create an instance of a model data class with sample data to test something out on a whim. Welp, this is a perfect use case for Chat-GPT. Let’s say I want to fill all the properties of this class to quickly test a composable function.

// 
data class BriefWeatherDetails(
val nameOfLocation: String,
val currentTemperature: String,
val shortDescription: String,
@DrawableRes val shortDescriptionIcon: Int
)

@Preview
@Composable
private fun Preview(){
.
.
CompactWeatherCard(
modifier = Modifier.padding(horizontal = 16.dp),
briefWeatherDetails:BriefWeatherDetails = //need a fake instance here,
onClick = { /*TODO*/ }
)
.
.

}

I can simply ask Chat-GPT to generate an instance of the class, filled with sample data.

Prompt : Create an instance of this class with sample data — “….”

A generated instance of the above class, filled with sample data

And Voila! There you go! Other than needing to change the resource id of the icon, I got an instance filled with sample data that I can immediately use! If I had mentioned the resource id, it would’ve probably correctly added it too!

Generating composable previews 📸

If you use Jetpack Compose, then this is for you! Setting up a composable preview can be a relatively time-consuming task. You have to create a new private function, annotate it with @Preview, surround the composable with your theme composable, and fill in the arguments of the composable with sample data. That's a lot of work just to see a preview of your composable!

Don’t worry! As you might’ve guessed! Chat-GPT has got your back! Just ask it to do all the work for you! Here’s an example.

// Here's an overload of the previous composable that doesn't depend on any 
// domain object. Let's ask Chat-GPT to generate a preview for us.
fun CompactWeatherCard(
nameOfLocation: String,
shortDescription: String,
@DrawableRes shortDescriptionIcon: Int,
weatherInDegrees: String,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {...}

Prompt: Create a preview composable for the following composable — “…”

Generated preview composable

It even filled the parameters of the composable with sample data on it's own, without even explicitly asking it to 🤯! Amazing!

Now, I wanted to surround CompactWeatherCard composable with a theme composable and a surface composable. So, I asked it to do the same.

Prompt: Surround the composable inside the preview with a composable named WeatherAppThemeComposable and a Surface composable

Generated preview composable inside a theme and surface composable

I noticed that the theme composable has the prefix “Composable” to it because I made a mistake in the previous prompt. Let’s correct it.

Prompt : Rename the WeatherAppThemeComposable to WeatherAppTheme

The generated preview composable with the “WeatherAppThemeComposable” renamed to “WeatherAppTheme”

And there you go! It did exactly what I asked it to do!

Conclusion

And, that wraps up this blog post 🎉 These are just a few use cases where I found Chat-GPT to be extremely useful. I’m sure I’ll find a lot more, the more I use it. I’ll make sure to share them as I find them. Did you find these use cases to be helpful? Let me know in the comments section.

As always, hopefully, you found this blog post helpful! If you liked this article, feel free to check out my other articles as well. I would like to thank you for taking the time to read this article😊. I wish you the best of luck! Happy coding 👨‍💻! Go create some awesome Android apps 👨‍💻! Cheers!

If you really liked my article and want to support me, you can do so, by clicking this link. Thank you so much for being generous ❤️, it really motivates me to keep going, and it helps me to keep my articles free for anyone to read. If you don’t feel like supporting, that’s fine too! The fact that you took some time off your schedule to read my article means a lot to me. Thank you 🙂

--

--

The Android Developer

| A very passionate Android Developer 💚 | An extreme Kotlin fanatic 💜 | A huge fan of Jetpack Compose 💙| Focused on making quality blog posts 📝 |