• Breaking News

    Sunday, January 30, 2022

    Android Dev - Ever wonder how Android Access View Items evolve over the years?

    Android Dev - Ever wonder how Android Access View Items evolve over the years?


    Ever wonder how Android Access View Items evolve over the years?

    Posted: 30 Jan 2022 02:30 AM PST

    For some, the PIP mode with Android 12 no longer works but the fix is ​​coming

    Posted: 30 Jan 2022 05:51 AM PST

    ViewModels & Compose: State/StateFlow/Lifecycle

    Posted: 29 Jan 2022 08:52 PM PST

    Rant/sanity check post about how to expose UI state/data from ViewModels when using Compose. Also, stuff gets annoying when Lifecycle needs to be involved.

    • I really like the idea of using State<T>s in ViewModels and not exposing Flows / StateFlows to composables (no additional boilerplate required for use in composables, works seamlessly)
    • But doing so really depends on how your business logic data is structured; if it is backed by a cold Flow or a hot Flow doing expensive work in the flow producer

    Case 1: Non-Flow Data Source

    Simplest case - no Flows in the picture, so State is an attractive option:

     class FooViewModel( private val getFooContent: GetFooContent ): ViewModel() { var state by mutableStateOf(FooState.Loading) private set init { viewModelScope.launch { state = getFooContent() // suspend func } } } 

    Case 2: Cold Flow Data Source

    If business layer data is backed by some cold Flow (or maybe even a hot Flow that isn't doing any expensive work like observing GPS, etc):

    • could use viewModelScope to collect the Flow and write to the State
    • although viewModelScope is larger than lifecycleScope of the corresponding Activity /Fragment, collecting the Flow here regardless of Lifecycle pause/resume could be ok if the source is cold or not doing expensive work when collecting

     class FooViewModel( private val coldFooContents: ColdFooContents ): ViewModel() { var state by mutableStateOf(FooState.Loading) // private set init { viewModelScope.launch { coldFooContents .onEach { state = it } .launchIn(viewModelScope) // viewModelScope should be ok? } } } 

    Case 3: Hot Flow Data Source

    If your data source implementation changes to a hot data source that runs expensive operations, such as reading GPS updates, etc, viewModelScope becomes too broad of a scope:

     class FooViewModel( private val hotFooContents: HotFooContents ): ViewModel() { var state by mutableStateOf(FooState.Loading) // private set init { viewModelScope.launch { hotFooContents .onEach { state = it } // viewModelScope keeps expensive operations running // need to involve Lifecycle to pause/resume work .launchIn(viewModelScope) } } } 

    Options in this case:

    • Option 1: Just expose Flow/ StateFlow in this case and use the Flow.flowWithLifecycle() APIs. This is SUPER awkward in Compose because conversion of StateFlow to State requires boilerplate:

     // Ugh? @SuppressLint("StateFlowValueCalledInComposition") @Composable fun <T> StateFlow<T>.collectStateWithLifecycle( lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle, minActiveState: Lifecycle.State = Lifecycle.State.STARTED ): State<T> = remember(this, lifecycle) { this.flowWithLifecycle(lifecycle, minActiveState) }.collectAsState(initial = this.value) // !! StateFlowValueCalledInComposition 

    • Option 2: Observe your hot data source in a LifecycleObserver, update a cache, and observe the cache in the ViewModel instead (obfuscate the fact that the original data is hot). You're back to the cold Flow case:

     // Attach HotDataLifecycleObserver to Activity/Fragment class HotDataLifecycleObserver( private val hotFooContents: HotFooContents private val updateCache: UpdateFooContentsCache ): DefaultLifecycleObserver { fun onCreate(owner: LifecycleOwner) { // collect hotFooContents with // repeatOnLifecycle/flowWithLifecycle APIs here // and call updateCache() // Don't forget to clear the cache at some point } } class FooViewModel( private val coldCache: ColdFooContentsCache ): ViewModel() { var state by mutableStateOf(FooState.Loading) // private set init { viewModelScope.launch { coldCache .onEach { state = it } .launchIn(viewModelScope) // viewModelScope should be ok } } } 

    Given all this, the choices are something like:

    • choose State<T> vs Flow/StateFlow + LifecycleObserver based on how business layer data is structured, OR
    • just expose StateFlows for all cases and deal with all the gross boilerplate, OR
    • use LaunchedEffect or some combination of side-effect APIs to read data in a smaller CoroutineScope??

    This stuff is super important and yet feels a little hand-wavy, awkward, and frustrating; maybe documentation/APIs or both need to improve (see this issue).

    Does anyone else share in the frustration, or otherwise have thoughts about this? What strategies do you use in your projects?

    Thanks for reading!

    submitted by /u/nebulasmoothie
    [link] [comments]

    How are people testing Compose Multiplatform apps?

    Posted: 30 Jan 2022 12:52 PM PST

    I'm looking into experimenting with Compose Multiplatform. I can't find much written on testing approaches and generally how to test apps like these? Is there a generally accepted way? What are people doing? Thanks so much for your advice

    submitted by /u/caldeve
    [link] [comments]

    MacOS Monterey with Android Studio

    Posted: 30 Jan 2022 11:32 AM PST

    Has anyone with an Intel chip MacBook Pro used Android Studio on MacOS Monterey? I've seen stuff that said the M1 MacBooks are fine. I'm curious if anyone has tested it with the Intel chip MacBooks?

    submitted by /u/sam_sepiol1984
    [link] [comments]

    Size of Samsung Galaxy clipboard (or ways to access it)

    Posted: 30 Jan 2022 10:41 AM PST

    I have a question about the Samsung Galaxy clipboard. After I found that it stored a huge list of items indefinitely and that it could not be automatically cleared, I made a Tasker process that flooded it with garbage periodically. But the newer phones have a massive clipboard, so copying 20 lines of garbage doesn't push anything off. I just end up with a growing mass of garbage. Is there a new size limit, or will this just keep increasing beyond any practical ability to push things out of its storage capacity?

    On a related note, do you know a way to access the clipboard on a non-rooted phone so it can be wiped or filled with garbage (automatically)?

    submitted by /u/plugubius
    [link] [comments]

    My app's similar apps are games

    Posted: 30 Jan 2022 07:54 AM PST

    Is this like a Google Play Store issue or something else? I have an entertainment app with fair amount of downloads and reviews (around 2K installs) and for starters my app is not suggested as a similar app on my competitor's store page and many of my similar apps section are actually games!

    submitted by /u/RadioactiveG
    [link] [comments]

    Real Time Voice Chat

    Posted: 29 Jan 2022 12:57 PM PST

    Hello, I'm currently in the process of building an application and need to implement a real time voice chat feature.

    The voice chat should enable either 1 on 1 communication inside a room, or a group of people communicating inside a room.

    I have started researching about webRTC and currently have the following understanding of how it works:

    One peer will create an offer asking another peer to connect with them.

    This will result in an SDP object or session description protocol.

    This data is then saved into a server where it will be read by another peer to answer the call. This is achieved by creating an SDP answer and writing that into the server.

    This process is called signaling and is handled by a 3rd party software -> firebase in my case.

    This signaling server allows the 2 parties to securely exchange connection data but never touches the media that is transmitted between the peers.

    but I've seen issues when using WebRTC were clients or (peers) on different networks cannot connect!

    I'm struggling with the general idea and how to go about solving it

    Any help in making things clearer are much appreciated!

    submitted by /u/ItsYourBoyAladen
    [link] [comments]

    I am quite surprised at what you can now do with Flutter

    Posted: 30 Jan 2022 03:21 AM PST

    Today I stumbled on a tracking app called MetriPort, it is made using Flutter and to my surprise it's quite neat: the UI looks nice and relatively complex, and the app runs quite smoothly even on my old phone (Samsung A8 2018). The developers of this app said that they are just a 2-man team and they made this app within just 3 months.

    This made me ask myself what else native Kotlin can do that Flutter cannot?

    Don't get me wrong, I like Kotlin and native Android development but seeing what Flutter can now do via apps like this, I am afraid that the future for new native Android devs like me might be a little bit uncertain?

    Also, is there any reliable statistics / chart for apps market share in 2022 by technologies / programming languages? I couldn't find one on Google. Thank you.

    submitted by /u/itachi8258
    [link] [comments]

    Flutter or Native Android [Job market]

    Posted: 30 Jan 2022 06:08 AM PST

    Hello dear community of Android Devs,

    I am currently a full stack engineer (mostly .net and react, sql, etc) and I am planning to move into mobile development.

    Currently I am taking a course on Flutter (by Maximilian Schwarzmüller) and I simply love the framework (it is the best development experience since I write code), the declarative composition, hot reload and state handling are simply amazing.

    However my goal is to move to the US and find a job in the mobile space and doing a quick research on the market seems like flutter is not really popular and the majority of recruiters are looking for native android.

    Looking a bit on the web I see in Android there is the new Compose way of doing things which is similar to Flutter's composition and state handling.

    My question is: Would it make sense for my situation (starting fresh on mobile) and goal (find a job in US) to just focus on native android with Compose or keep going with Flutter?

    I see no strong support for niche things like accessibility or WearOS support from Flutter (I am not sure how much this counts in terms of job opportunities). There is one thing makes Flutter more appealing (at least future-wise), this being the active development of https://fuchsia.dev/ OS which judging only based on what I read, I have a feeling that this might go big in few years. Also the cross platform + performance of Flutter its a very nice thing to have.

    Any input is much appreciated.

    submitted by /u/PuzzleheadedUnit1758
    [link] [comments]

    How to detect autoclick on layout in java?

    Posted: 29 Jan 2022 10:18 PM PST

    Hi guys,

    I'm wondering, how to detect autoclick on a layout without to use any services. Maybe intercept clicks and check gestures and click paramteres? What do you think? Is is worth to implement some code or the autoclicker apps are nowadays too clever that they can simulate clicks like it would be a human click?

    Thanks!

    submitted by /u/frinor
    [link] [comments]

    Creating an app on fiverr

    Posted: 29 Jan 2022 08:11 PM PST

    Hi all,

    I have an app idea but I have zero experience in coding. I was thinking of hiring someone overseas on fiverr for development of an app. A quotes based app, where the app generates one quote per day. It would have other details as ability to set when the quote is issued in the day, acknowledgement page, add some ads on a page, ability to pay and remove ads. I see pricing coming in for me around $400-$800 for the app. Has anyone done created an app off Fiverr and how did it go? Is this price point reasonable for a daily quotes app or is it going to lead to a low quality app?

    Thanks!

    submitted by /u/ksing_king
    [link] [comments]

    Android Dev Hangout - monthly informal gathering for our community

    Posted: 29 Jan 2022 10:26 AM PST

    Wanted to share an event myself and a friend organize...it is a monthly meeting that is designed to be an informal gathering of Android devs...we took our inspiration from the popular "iOS Dev Happy Hour" (and even got their help organizing it).

    Our Jan event is in 20 minutes, so it is not too late to join today.

    You will need a free ticket to attend (we only share the Zoom with ticketed members).

    If you can't join today, please join next month.

    submitted by /u/boogermike
    [link] [comments]

    No comments:

    Post a Comment