https://kotlinlang.org logo
Join SlackCommunities
Powered by
# android-architecture
  • y

    Yuvaraj

    04/20/2024, 12:05 AM
    I'm working on sample project which will use multiple SDK for same functionality. For example i have SDK A,B and C Now I have build a separate modules for all the three sdk and one X module to map to common features in SDK When I set the current environment for a specific SDK then X module should have dependencies, build and generate aar only with given specific SDK. Once the X module is build with SDK A then app should be able to generate apk or .ipa I'm using KMP to build this app. The SDK can be of Android and iOS some might support only Android or only iOS. How can i configure my gradle in KMP to build for this use case.
    m
    • 2
    • 2
  • r

    Rudy Sulley

    05/15/2024, 5:40 PM
    Was curious what we all think of the new type safe navigation with compose navigation and what way you would possibly implement it neatly in code. I have thought of using a sealed class or probably a similar construct
    Copy code
    sealed class Screens {
        @Serializable
        data object Home : Screens()
    
        @Serializable
        data object About : Screens()
    }
    Copy code
    fun NavGraphBuilder.aboutScreen(
        modifier: Modifier = Modifier,
        onBackButtonClick: () -> Unit,
    ) {
        composable<Screens.About> {
            AboutScreen(
                modifier = modifier,
                onBackButtonClick = onBackButtonClick,
            )
        }
    }
    Or would you throw each route definition in separate files, probably where the composable is defined or within their respective packages? Slack Conversation
  • r

    Raji

    06/05/2024, 1:15 PM
    what is the best way to include analytics on presentation layer or data layer ,if I have to send a comprehensive information with each event i will log
    a
    s
    • 3
    • 4
  • r

    raghunandan

    06/14/2024, 3:01 AM
    we have forms where we collect some details from users. the form spams to 4 screen. Data is different in each screen. So one of my colleagues used different viewmodels for each of them. I am against it. I asked them to move the validation and other application logic to usecase. Do you think my suggestion was right?. After the last step we will need to send details to server via api. Is there a better way to handle this?.
    g
    c
    • 3
    • 6
  • c

    Christopher Mederos

    06/20/2024, 5:54 AM
    I'd like to let users select between imperial & metric units in my app. How are folks accomplishing this in their own apps? I'm considering
    CompositionLocal
    since units are usually 4-6 children deep in my composable hierarchy. I'm thinking of storing the setting in my cache (realm), making it available in a viewmodel, collecting the state and making it available via CompositionLocalProvider just above my NavHost. Then I'd pass the viewmodel method reference to update the setting values to my "settings screen" composable. Is that reasonable? Is that easier than passing a UnitsPreference arg a bunch of times? Thanks!
    s
    c
    • 3
    • 8
  • r

    raghunandan

    07/05/2024, 2:38 AM
    I have different section on my home screen. Each section data source is different api. So i used lazy column. I want lazy load each section as i scroll to the end. On the view based system for a similar feature implementation i was using contact adapter. So i can do the same with lazy column each section with item. This works. But i want lazy load second section one when user scrolls to end of first section. Section content is dynamic. Any suggestions on how to handle this better?
    • 1
    • 2
  • s

    Suraj Shukla

    07/13/2024, 5:20 PM
    I have a text inside my recyclerview I want to animate it after some delay, can I use coroutine job inside my onBind or shall I use handler for that?
  • j

    Joost Klitsie

    07/26/2024, 10:30 AM
    Perhaps interesting for this channel as well
    👀 1
  • a

    anlex N

    08/21/2024, 9:44 AM
    hello every, Is [modern android architecture](https://developer.android.com/topic/architecture) based on [togaf](https://pubs.opengroup.org/togaf-standard)?
    p
    d
    +2
    • 5
    • 20
  • a

    anlex N

    09/22/2024, 2:41 AM
    @Ryan Casler Have you tried Unity?
  • a

    anlex N

    09/29/2024, 1:13 PM
    Hello everyone, today, I know modern android architecture is a layered architecture. But I wonder whether system architecture is also a layered architecture in the google ? for example, [google store](https://store.google.com/).
  • d

    Daniel Okanin

    10/08/2024, 5:34 PM
    Hello everyone I’m working with an architecture design system using MVI on Android. I fetch the
    Model
    data from the server and use a transformer in the
    ViewModel
    to create a
    UiModel
    specific to the view. I’m wondering: when I need to display an icon based on the
    UiModel
    , should I include the drawable resource (
    @DrawableRes
    ) directly in the
    UiModel
    class? Or, should I include a type field and map the drawable resource in the view layer itself? Which approach is considered best practice? If I go with the first approach, the view stays very simple since it only needs to display the data. However, I’m unsure if this is the best solution for maintainability or flexibility
    a
    m
    d
    • 4
    • 7
  • v

    Varun Sethi

    10/10/2024, 5:12 AM
    Hi
  • v

    Varun Sethi

    10/10/2024, 5:14 AM
    can I ask for learning resources about multi module and clean architecture over here
    s
    v
    • 3
    • 8
  • r

    Raju Kulo

    10/17/2024, 11:38 AM
    Hello everyone I always wonder whats the best way to share between 2 different screens in android. For eg: Im creating a record in create page + create view model. From there, Im inserting list of subform data for which im invoking Subform page. Once subform data are filled, I need to transport this list data from subform screen to create screen, where I will show them as table. Also, some data like org, user data from API needed to be available throughout all the screens. So what's the best way to do this ? Shared VM/DB caching/Hit server api in all screens or any other way ?!
    c
    a
    • 3
    • 3
  • k

    Kashismails

    10/28/2024, 7:06 PM
    Is it really true that if using MVI, there should be only one state? I like to have different states for different parts of screen so these can update independently and it also makes it hard to maintain if you put everything in one class. Is my understanding wrong?
    waving from afar right 1
    a
    m
    c
    • 4
    • 9
  • p

    Peter

    11/05/2024, 10:52 AM
    Does anyone know for a tool, that allows you to visualize or print-out dependencies between classes? Something like poor mans https://www.jetbrains.com/help/idea/class-diagram.html#analyze_class
    • 1
    • 1
  • l

    Luke

    11/26/2024, 2:48 PM
    If this is not the right place to ask this, please direct me to the proper channel I have an implementation of an interface that looks like this:
    Copy code
    interface MyRepository {
        val state: StateFlow<State>
    	
        sealed interface State {
            data class Foo(...): State
            data class Bar(...): State
        }
    }
    Now, I need to run some code each time the state changes while the application runs. What is the best way to set a collector on the state and test that the collector works properly?
    e
    j
    • 3
    • 3
  • m

    Mohammed Akram Hussain

    11/29/2024, 12:11 PM
    Copy code
    @HiltViewModel
    class HomeViewModel @Inject constructor(
        repository: Repository
    ) : ViewModel() {
    
        val uiState = repository.data
            .mapLatest { result ->
                when (result) {
                    is Result.Success -> UiState.Success(result)
                    is Result.Error -> UiState.Error(result.exception.message ?: "Unknown error")
                }
            }.stateIn(
                scope = viewModelScope,
                started = SharingStarted.WhileSubscribed(5.seconds.inWholeMilliseconds),
                initialValue = UiState.Loading
            )
        
        sealed class UiState {
            data object Loading : UiState()
            data class Success(val data: Data) : UiState()
            data class Error(val message: String) : UiState()
        }
    }
    
    class Repository @Inject constructor(
        private val api: Api
    ) {
        private val _data = MutableStateFlow<Result<Response>?>(null)
        val data = _data.asStateFlow().filterNotNull()
    
        suspend fun getData() {
            try {
                val response = api.getDataFromNetwork()
                if (response.isSuccessful) {
                    val body = response.body()
                    if (body != null) {
                        _data.emit(Result.Success(body))
                    }
                } else {
                    val exception = Exception("Server Error: ${response.code()}")
                    _data.emit(Result.Error(exception))
                }
            } catch (e: Exception) {
                _data.emit(Result.Error(e))
            }
        }
    }
    The above is the approach suggest in the architecture samples HERE but I don't understand how it'll work for network call where caching or offline support is not required. The two main problems I am facing with this approach for the above are: 1. How should I trigger the initial data load when the screen opens? 2. What's the best way to implement a refresh mechanism (like pull-to-refresh)? Is this Flow-based approach overkill for simple network calls without caching? Should I consider a different approach? Would appreciate any guidance or best practices!
    a
    • 2
    • 8
  • e

    Evan Holtrop

    01/02/2025, 4:47 PM
    Looking to dive deep, is there any documentation on the general structure of our android apps?
  • d

    Daniel Okanin

    01/09/2025, 4:54 PM
    Hey everyone, I wanted to get your thoughts on an architectural approach. I'm planning to create a screen in Jetpack Compose that contains multiple Compose components, where each component is responsible for fetching its own data. This would mean that each component would need its own ViewModel, etc. What do you think? Pros and cons?
    a
    r
    j
    • 4
    • 10
  • s

    Su Van Ho

    01/17/2025, 7:39 AM
    https://github.com/android/nowinandroid/discussions/1273 -> #til Google does not follow Clean Architecture
    the domain layer depends on the data layer
  • a

    Abhishek Sharma

    01/24/2025, 1:35 AM
    Hello, In a clean architecture(image taken from here), we have multiple features (e.g.,
    :feature:home
    and
    :feature:reviews
    ) that need a use case combining data from two domain modules (
    :domain:books
    and
    :domain:reviews
    ). For example,
    Feature A
    and
    Feature B
    both require data that comes from a composition of
    BooksUseCase
    (from
    :domain:books
    ) and
    ReviewsUseCase
    (from
    :domain:reviews
    ). A few approaches come to mind: 1. Create a new module (e.g.,
    :domain:books-reviews
    )
    to house the combined use case logic. However, this introduces horizontal dependency, as the new domain module depends on both
    :domain:books
    and
    :domain:reviews
    , potentially violating clean architecture principles of vertical dependency. 2. Place the combined logic in a common domain module (
    :domain:common
    ). But in a large app, this could lead to bloating and tightly coupling unrelated shared logic in a single module. 3. Move the composition logic to the feature layers and directly invoke the relevant use cases from the domain modules. However, this risks duplicating logic across multiple features if the combination logic is reused. What is the best way to handle this scenario while maintaining modularity, scalability, and adherence to clean architecture principles? Is it acceptable to have a cross-domain dependency in such cases, or should the logic live elsewhere (e.g., feature layer or backend)? Any recommendations or best practices for managing such cross-domain use cases in large apps?
    a
    j
    a
    • 4
    • 10
  • m

    Matti MK

    02/12/2025, 1:58 PM
    I am following the Modern Android App Architecture in my app that's offline first, and I'm not quite certain on what kind of an approach to take with handling data in my Repositories. To me it seems that
    Store
    (https://github.com/MobileNativeFoundation/Store) would be a valid option, as well as using the
    NetworkBoundResource
    pattern. Has anyone used
    Store
    ,
    NetworkBoundResource
    or another approach?
  • m

    mattinger

    02/12/2025, 7:38 PM
    Has anyone here used Hilt in a large scale application? We have a ton of features in our app, and thus have a lot of modules, and a decently sized object graph. We're currently using anvil, but we're considering moving to hilt since anvil seems a ways off from supporting the k2 compiler, and that's a big negative for us. Hilt seems to keep up to date with kotlin and dagger (which makes sense since it's maintained by google who works closely with jetbrains, where anvil doesn't really seem to have that corporate type backing). All things being equal, i prefer the flexibility of anvil, but the lack of K2 support is big detractor. I'm just concerned about moving all our things that were in contributed subcomponents into the singleton graph. I don't think we're anywhere near the 255 modules it would take to break the jvm limit on constructor parameters, but just more concerned with the overhead. I also don't know how custom hilt components work with things like entry points. Also, for those that do use hilt, do you put your ViewModelFactory instances in the Singleton scope, or in the Activity/Fragment scope?
    j
    l
    k
    • 4
    • 5
  • r

    Raj Paliwal

    02/28/2025, 5:40 PM
    Hello everyone, I am facing an issue where my app is being killed, and in the Exit Information, I see the following details: • Reason:
    OTHER_REASON
    • Description:
    ScreenOffCheckKill 26m3s4ms (26.33344%) threshold 2.0%
    The issue occurs when a*fter screen turns off, app in background.* The description in the exit logs suggests ScreenOffCheckKill, but I couldn’t find any official documentation explaining this behavior. • What exactly does
    ScreenOffCheckKill
    mean, and why does it happen? • Is this a system-level restriction or a configurable setting? • How can I prevent my app from getting killed due to this reason? • Any pointers to official documentation or similar cases would be highly appreciated. Thanks in advance for any insights!
  • k

    KotlinLeaner

    03/07/2025, 6:25 PM
    Hi, My Android app uses Ktor for network requests, and I have a separate module for handling API calls. I've implemented 401 error handling to trigger a logout. However, my navigation logic, including the NavHost, is in the app module. What's the best way to signal the NavHost to perform the logout action when a 401 error occurs?
    m
    v
    +2
    • 5
    • 5
  • f

    Filippo De Pretto

    03/23/2025, 12:31 AM
    Hi guys, in case you have a lot of callbacks, in particular when you have also some components inside, so you have to pass those callbacks down, what is your favorite approach instead of passing all the callbacks? I've seen the possibility to pass a onAction function or use MVI, but I was wondering what is your favorite approach. Any suggestion is appreciated 🙌
    m
    k
    +2
    • 5
    • 5
  • n

    Novo Dimaporo

    04/23/2025, 5:44 AM
    Hi guys, 👋 I was wondering if it is possible to execute a room db transaction in the a usecase. Is it a good idea, I was thinking of creating a dao that looks like this
    Copy code
    @Dao
    interface EntityDao {
        @Transaction
        fun transaction(block: () -> Unit) {
            block()
        }
    }
    And expose this to the repository layer then the usecase.
    r
    • 2
    • 7
  • u

    Usman

    05/06/2025, 6:05 AM
    Hlo friends! I,mhave pretty good experience in android jetpack Sdk , kmp , compose multiplatform, iOS swiftUI and also API development using python flask or ktor server or I can Handel database that is SQL or noSQL and I can work with Supabase Firebase Python anywhere Postgresql So the main thing is if there is anyone who is on that level and don,t have any job or freelancing project just connect with me we will talk hai see why we don,t get a job why we don,t get paid
    🚫 3
    • 1
    • 1