• Breaking News

    Tuesday, February 22, 2022

    Android Dev - Weekly Questions Thread - February 22, 2022

    Android Dev - Weekly Questions Thread - February 22, 2022


    Weekly Questions Thread - February 22, 2022

    Posted: 22 Feb 2022 06:00 AM PST

    This thread is for simple questions that don't warrant their own thread (although we suggest checking the sidebar, the wiki, our Discord, or Stack Overflow before posting). Examples of questions:

    • How do I pass data between my Activities?
    • Does anyone have a link to the source for the AOSP messaging app?
    • Is it possible to programmatically change the color of the status bar without targeting API 21?

    Large code snippets don't read well on reddit and take up a lot of space, so please don't paste them in your comments. Consider linking Gists instead.

    Have a question about the subreddit or otherwise for /r/androiddev mods? We welcome your mod mail!

    Also, please don't link to Play Store pages or ask for feedback on this thread. Save those for the App Feedback threads we host on Saturdays.

    Looking for all the Questions threads? Want an easy way to locate this week's thread? Click this link!

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

    �� Contact Store 1.0 is now available! – a modern, simpler way of accessing contacts in Android

    Posted: 22 Feb 2022 03:13 AM PST

    A few months back, I posted about a modern alternative to the Contacts API I was working on called ContactStore.

    The post received 100 upvotes and plenty of positive comments!

    More than ⭐️ 260 Github stars, 🍴 9 forks, 💙 2 contributors, plenty of feature requests and with incredible support from the Android community, Contact Store just hit 1.0 🍾 and there are going to be no breaking changes from now on.

    Contact Store is not simply a strongly-typed version of the default API, but a modern, simpler way of accessing contacts in Android.

    Forget about RawContacts, Entities and overwhelming documentation. ContactStore provides a simple API so that you can use contacts straight away and focus on your app's important features instead.

    The way to access all contacts on the device is as simple as:

    val store = ContactStore.newInstance(application) val job = store.fetchContacts() .collect { contacts -> println("Contacts emitted: $contacts") } // don't forget to job.cancel() 

    .collect {} will provide new values, everytime the contacts are updated.

    There are also optional Coroutines and rxJava extensions you can use:

    val store = ContactStore.newInstance(application) val disposable = store.fetchContacts().toFlowable() // or toFlow() for coroutines .subscribe { contacts -> println("Contacts emitted: $contacts") } // don't forget to disposable.dispose() 

    Fetching details for a specific contact is also straightforward:

    val store = ContactStore.newInstance(application) store.fetchContacts( predicate = ContactLookup(contactId), columnsToFetch = listOf(Phones, Mails, Note) // or allContactColumns() for all data ) .collect { contacts -> val contact = contacts.firstOrNull() if (contact == null) { println("Contact not found") } else { println("Contact found: $contact") // You can now use contact.phones, contact.mails, contact.note } } 

    there is also a Kotlin DSL for writing contacts. Here's an example how to create a new one into a Gmail account:

    val store = ContactStore.newInstance(application) store.execute { insert(InternetAcount("paolo@gmail.com", "gmail.com")) { firstName = "Paolo" lastName = "Melendez" phone( value = PhoneNumber("555"), label = Label.PhoneNumberMobile ) mail( address = "paolo@paolo.com", label = Label.LocationWork ) } } 

    This is just a quick overview of ContactStore. ContactStore can do so much more:

    • search a contact using part of their phone number, mail or name
    • load high res Contact images
    • provide utilities for testing contacts without Robolectric
    • formating phone numbers & postal addresses for UI purposes
    • support for all data kinds of contacts (phone numbers, e-mails, postal addresses, structured name, events and more)
    • load custom items such as call on WhatsApp or video call on Telegram

    The API documentation covers all the functionality available along with code samples and best UX practices: https://alexstyl.com/contactstore/

    If you find this API useful, 🌟 give a star on Github and 🐦 follow @alexstyl on Twitter for updates.

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

    What's your review of AppLovin? I had really bad experience with them when I added their network for few days back in 2020. Insanely high clicks, but literally non-existent revenue.

    Posted: 22 Feb 2022 03:33 AM PST

    What's your review of AppLovin? I had really bad experience with them when I added their network for few days back in 2020. Insanely high clicks, but literally non-existent revenue.

    I have to migrate from MoPub onto their AppLovin Max platform for mediating my ads. Unfortunately it looks like you cannot disable AppLovin's own ad network (in MoPub, you could disable their marketplace + bidding if you wanted to).

    Here's the eCPM that I got for Tier 1 countries (US, UK, Germany, Canada, etc).

    https://preview.redd.it/7pha6ipcedj81.png?width=2674&format=png&auto=webp&s=4be5466a0d1454001d12eadb53d6478bd1ed6298

    As you can see, I ran the ads only for 2-3 days, and concluded that it wasn't worth my time to continue with them. Almost 8197 impressions to get $0.73 chump change for 200 clicks!

    And I can 100% assure you that this was Tier 1 country traffic that was giving me such bad eCPM.

    How's your experience with AppLovin MAX? Is their eCPM now comparable to MoPub at least?

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

    What to use for updating the UI from a Service (LiveData, Kotlin Flows, Repository)?

    Posted: 22 Feb 2022 04:00 AM PST

    At first I want to say that I'm still at the start of Android development and trying to learn what (and why) is "recommended" way of doing things.

    I'm currently writing an app which uses a service which continously scans for Bluetooth beacons (also in the background when the Activity is stopped) and an Activity which should display the results.

    Therefore, I currently use a bound service to have a reference to the service object in my Activity for communication from Activity -> service.

    The service holds all the found beacons in a List object and notifies the Activity for new beacons via a LocalBroadcast. The adapter displaying the beacons directly uses the list maintained by the service (in order to have a "single source of truth" (SSOT)).

    The problem is that since found beacons are added asynchronously into the adapter list by the service (via the ScanCallback), the UI (and thus the adapter) sometimes (when many beacons are found the same time) takes too long to update it's RecyclerView with the new data and ends up with an "inconsitency detected" crash since the underlying list was changed too fast and asynchrounously.

    After researching I found that you should not change adapter data asynchrounously. I came across LiveData (in combination with a ViewModel) and Kotlin Flows. In addition, I came across the "Repository" design pattern as another approach. I still want to have a SSOT for the list and I am now uncertain what is the "proper way" to achieve displaying updates in the UI from data which is modified (asynchrounously) in a service.

    The approaches I considered were:

    • Using Kotlin Flows to update a ViewModel from the service. The ViewModel then "notifies" the Activity (observer) via LiveData
    • Using LiveData to directly update the Activity about list changes from the service (though I read LiveData should not be used for asynchrounous operations)
    • Using a Repository class to centrally store (service) and read (Activity) the list
    • Letting the service store the results in a database and let the Activity display the contents of the database and get updates via LiveData (or Flows?)

    I would be grateful for a hint what would be the adequate pattern to use in such a situation.

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

    Android Gaming performance

    Posted: 22 Feb 2022 06:34 AM PST

    I play mobile games on a tab s6. Not knowing much about the OS or optimization, I am wondering what knowledge some of you might be able to share on it. In communities like fortnite mobile, the player base desires more FPS like 120 on devices and to have better graphics but it continues not to be supported. What criteria would a tablet need to perform at such a level?

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

    Android export and import data. It tackles how to backup and restore the data of local storage If app is deleted or uninstalled.

    Posted: 22 Feb 2022 05:26 AM PST

    Kotlin bluetooth documentation is outdated

    Posted: 22 Feb 2022 03:45 AM PST

    Hi, i recently tried to use kotlin to create a Bluetooth connection. On the official documentation some code show in the examples is outdated and android studio doesn't recognize it. Can anybody help? Also is there maybe a complete Bluetooth template in kotlin? Thanks

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

    No comments:

    Post a Comment