Home > Software engineering >  How to use Android Studio Activities
How to use Android Studio Activities

Time:11-30

I'm new to Kotlin and Android studio, I previously completed a project of mine with KivyMD, I want to replicate the project with Kotlin using Android studio, the project has 56 screens, I've learnt that activities represents screen in Android Studio, which means I'll have to create 55 more activities in additional to MainActivity, thinking that might be a bit much I googled if they is a limit to number of activities I can create I found it's 10..

So how do I put the contents of other screens? or Could I just go ahead and create all 56 activities??

Thanks to you for your help in advance..

CodePudding user response:

Jetpack is a bunch of libraries created to ease app development and help people follow best practices, and the official recommendation is a single-Activity app:

Navigation

While activities are the system provided entry points into your app's UI, their inflexibility when it comes to sharing data between each other and transitions has made them a less than ideal architecture for constructing your in-app navigation. Today we are introducing the Navigation component as a framework for structuring your in-app UI, with a focus on making a single-Activity app the preferred architecture.

By using the Navigation component, your Activity is basically a container for Fragments, which act as your "screens". Navigation handles a lot of the boilerplate for swapping them in and out and maintaining history, and you focus more on connecting them together in a navigation graph.

It's a lot to learn at first, but it's definitely worth it, and if you're going to be messing with 56 destinations then you'll probably end up saving a lot of time letting it handle the bulk of the work! Here's a codelab tutorial you can do to get up to speed with it, and here's the documentation which starts with the basics and gets to some of the more complex uses

  • Related