Chapters

Hide chapters

Android Fundamentals by Tutorials

First Edition · Android 14 · Kotlin 1.9 · Android Studio Hedgehog (2023.1.1)

7. Advanced Architecture
Written by Fuad Kamal

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In the last chapter, you improved the chat app by implementing ViewModel and Flows and making some UI improvements. In this chapter, you’ll learn about another important architecture pattern in mobile development: the repository pattern. You’ll also learn how to use a revolutionary new P2P mesh technology via the Ditto SDK to finish the Kodeco Chat app and enable communication between devices without cloud service.

Ditto SDK

Now, you’re able to add real chat messages in your app. But what’s the use of a chat app if only one device or person can chat? That’s only a conversation if you enjoy talking to yourself!

So you need a way for devices or people to chat with each other. This is where the Ditto SDK is handy. Ditto is a cross-platform P2P SDK that lets two devices communicate using any type of wireless transport — Bluetooth, Wi-Fi, etc. — without an internet connection or cloud back end.

Registering Your App With Ditto

You’ll need to create a developer account with Ditto and build a personal app on its website. This gives you access to the authentication keys needed for the SDK. In a web browser, navigate to Ditto.live and click the Get Started button. Then, follow the steps to create an account. The simplest way is to sign up with your existing Google account. Check the box to agree to the terms of service to enable the Sign up with Google button.

Setting Up Ditto SDK in Your App

You need to add the Gradle dependency for Ditto in your app, so open the starter project of this chapter. Open libs.versions.toml and, in the [versions] section, add:

Repository Pattern

Sometimes, you want to store and fetch data from a local database in your app. Other times, you might want to fetch data from the internet or a cloud service using a networking API. And sometimes, you want to fetch data from the network. But if the network isn’t available, you’ll want to fetch the same data from a local cache you created the last time the network was available. In other words, you might want to combine both network and local data.

Key Points

Well done! In this chapter, you’ve covered so much ground and created a real-world, P2P Android chat app! To recap, you learned:

Where to Go From Here?

For a more in-depth look at app architecture and design patterns, check out the book Advanced Android App Architecture.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now