/r/androiddev

Photograph via snooOG

News for Android developers with the who, what, where, when and how of the Android community.

News / Articles / Talks / Tools / Open source!

About

News for Android app developers with the who, what, where, when, and how of the Android community. Probably mostly the how.

Here, you'll find:

  • News for Android developers
  • Thoughtful, informative articles
  • Insightful talks and presentations
  • Useful libraries
  • Handy tools
  • Open source applications for studying

Alternatives

This sub-reddit isn't about phones' and apps' general functionality, support, or system software development (ROMs). For news and questions about these topics try using other subs like

New Developer Resources

Build your first app

Starting Android career in 2022

Android Job Interview Questions and Answers

App Portfolio Ideas, Tiered List

Awesome Android UI

Material Design Icons

7000 Icons for Jetpack

Weekly Threads Calendar

Autoposted at approx 9AM EST / 2PM GMT

Links

Rules!

Wiki and FAQ!

Discord!

/r/androiddev

243,807 Subscribers

41

Kotlin introduced awful discoverability. How do you guys keep up?

Hello guys!

I've been working with Kotlin for a few years and the last 2 with Compose. I'm a big fan of both.

Nevertheless, one of the things that I find really unfortunate is the awful discoverability that Kotlin introduced in the ecosystem. I used to learn a lot just by navigating and reading through code/packages/libraries, but now everything is so spread out that it makes it impossible.

I've recently came across "Extension-oriented Design" by Roman Elizarov which expands on why this was the choice for Kotlin and I enjoyed the article.
But surely there should be an easy way to allowed devs to keep up to date, right? Right?

E.g. 1:
Previous to Kotlin, if I'd want to perform some transformations on collections, I'd go into the Collection interface or take a look at the package and find some neat methods that would steer me in the right path.
Nowadays it'll be some extension that will be hidden in some package that I must include as a dependency that is almost impossible to find unless you know what you're looking for.

E.g. 2: I was trying to clean up some resources, android compose documentation hints `onDispose` method. Only by chance today I found there is LifecycleResumeEffect - which seems much more appropriate and up-to-date.

TL;DR - I think it's very hard to discover new methods / keep up to date with functionality (Kotlin & Compose) when it is spread out over X packages / libraries.
Do you agree? How do you navigate that? Am I missing some trick?

13 Comments
2024/12/03
11:57 UTC

29

Introducing SmolChat: Running any GGUF SLMs/LLMs locally, on-device in Android (like an offline, miniature, open-source ChatGPT)

5 Comments
2024/12/03
11:50 UTC

2

Automatically extract strings to strings.xml

Is there any Android Studio plugin to automatically extract all hard coded strings and put in strings.xml file?

2 Comments
2024/12/03
06:05 UTC

6

Splitting up a ViewModel via Delegation for modularity and single responsibility principle

Is anyone out there slicing up their ViewModels to encapsulate related functionality for modularity and facilitation of simpler testing with Mocks?
Example:

class MyViewModel @Inject constructor(
    private val delegate: HelperVMDelegate.Factory,
    private val scope: ViewModelScope,
) : ViewModel(scope), HelperVMDelegate by delegate.create(scope) {

I am getting pushback from some on this because:

  1. They fear that coworkers might try to use the delegate class directly because it might not be clear enough, so I suggested I could just create and add a \@ViewModelDelegate annotation to help make it extra obvious that it should not be directly used.
  2. The idea of passing the ViewModel's scope to something that "isn't" a ViewModel, but a helper delegate, seemed wrong to them.
  3. The use of lifecycle aware code "outside" of the ViewModel, such as LiveData is generally wrong, but this isn't really outside of it. Would you still convert to Flows just for the sake of it?
17 Comments
2024/12/02
22:40 UTC

0

Having trouble with your specific project? Subreddit updates and more: This is the December 2024 newbie and advice thread!

Career Advice

This is a reminder that this Subreddit isn't for career advice. We regularly see posts asking how the job market is, or whether Android development is a good career, or if it's a good thing to add to a resume. We don't allow these questions for two reasons. First, the market is constantly changing, and differs enormously depending on location, politics, and the time of year. Second, a person's likelihood of success is dependent on their tenacity, skill, and experience. A job coach, developers at a local meetup, or simply looking up jobs in your area on LinkedIn will give you more meaningful information than replies on here.

If what you're really asking is, "can I easily learn this and make a lot of money shoveling an ad-ridden copycat game onto Google Play"... no. If you're new and trying to fine-tune your skills, you can ask your question here in the "newbie and advice" thread.

Sales and Marketing vs. Application Development

This is a reminder that this Subreddit isn't for marketing advice. Yes, if you are an independent developer how you market your app, how you price it, and making sense of sales and impression trends are all important. However, that is a separate skill set from application development. There are excellent communities of professionals that should be your preferred source of information. That said, questions regarding sales and marketing will be allowed here in the "newbie and advice" thread.

Doing Your Work

This is a reminder that this Subreddit isn't a replacement for learning or working with your team. Although we now allow questions that are of general interest to the development community, we expect the question to demonstrate a baseline knowledge of Android development and that it should prompt a healthy discussion between professionals. There has been a recent rise in questions that are at once too broad and too specific. These questions generally amount to "walk me through how to develop this core feature of my app". It's often couched in different ways. "Is it possible to do this...", "Can someone partner with me...", "How would you implement...", but the result is the same. If you want to have this kind of discussion, please join our Discord server, or reserve the questions for this "newbie and advice" thread.

So, with that said, welcome to the December 2024 newbie and advice thread! Here, as usual, we will be allowing basic questions, seeking situation-specific advice, and tangential questions that are related to but not directly Android development.

If you're looking for the previous October 2024 thread, you can find it here.
If you're looking for the previous November 2024 thread, you can find it here.

Happy holidays, and wishing everyone the best as we wrap up 2024,
The Mods

4 Comments
2024/12/02
22:21 UTC

4

Compose UI Testing with ExoPlayer3

Hi Android Community! I was wondering if anyone has been able to do compose testing with ExoPlayer3 video and if you are able to mock or play a local video. I’ve looked around online but see really limited resources on this and was wondering if it’s possible! There doesn’t seem to be much documentation around testing ExoPlayer as well.

6 Comments
2024/12/02
21:21 UTC

26

Can you review my refused android app challenge?

I did an application to a junior android position where they asked me to develop a challenge to fetch and use the GitHub API.

I did it and the final result worked well, however they decide to not do a technical interview with me.

At least, they give me feedback which I would like to know if you agree with them, and if was your case you also didn't go with the next interview.

Positive points

Use of appropriate tools: It was clear that you have a solid foundation and are familiar with some of the important tools for

Complete functionalities: All the functionalities requested in the challenge were implemented, which demonstrates attention to the requirements

Well-structured pagination: The use of pagination was executed effectively, showing a good understanding of this

Presence of navigation: Despite some points for improvement, the application includes navigation, which is always positive.

Areas for Improvement

Implementation of Flows: Despite having mentioned the use of Flows, the practical implementation does not correspond to what was expected, except for the pagination part. It is important to align the use of the tool with good practice and the purpose described.

Lack of Dependency Injection (DI): The lack of DI compromises the scalability and organization of the code, and is an essential point to consider in future

Inconsistent architecture: Although there was an attempt to structure the application, the use of ViewModels was lacking. Instead, there was an excessive use of LaunchedEffects to bridge this gap, which is not a recommended

Lack of repository layer: A repository layer was not implemented, which is essential for separating responsibilities and improving code

Problems with the Home Screen: The implementation of the Home Screen presents some choices that could be simplified. For example, the use of Scaffold and Column would have been sufficient, avoiding redundancies such as multiple containers, remembers and unnecessary LaunchedEffects.

Use of viewModelScope.launch: Although I tried to use viewModelScope.launch(Dispatchers.IO), its application was not correct, and it deserves special attention for future projects.

I mean, I agree with them in some cases, but I wouldn't definitely refuse an interview because of them, given that was a junior position.

Can you give me your opinion? This is the github link: https://github.com/andrecasal00/bliss-challenge

44 Comments
2024/12/02
14:05 UTC

1

How to Handle Touch Events Going Out of Sync with Render Loop in GameActivity?

I am working on an Android project using the GameActivity template in Android Studio. I've encountered an issue where touch events sometimes go out of sync with the render loop. When this happens, I do not receive any touch events for the current frame, and the missed touch events are instead received in the next frame.

My Questions:

  1. How can I fix this synchronization issue? Is there a way to ensure that touch events are processed in the same frame they are received?
  2. Can I increase the frequency of onTouchEvent without changing the frame rate? I want to handle touch inputs more frequently without impacting the render loop's frame rate.
  3. Is there an alternative method to receive touch events at a higher rate than the frame rate? I am looking for ways to decouple the touch event handling from the render loop, possibly processing touch inputs at a much higher frequency.

Any insights, workarounds, or solutions would be greatly appreciated!My Questions:How can I fix this synchronization issue?

https://preview.redd.it/qn9jv9opo64e1.png?width=471&format=png&auto=webp&s=79e7cd62ccd7a65f0e9b38404d0e844a28dc0a65

2 Comments
2024/12/01
06:48 UTC

26

Surface.setframerate() doesn't work on Xiaomi phones?

Hi,

im using surface.setFramerate() with the parameter " Surface.FRAME_RATE_COMPATIBILITY_DEFAULT" to set the users display to match with my games FPS which is 60, however changing the hz doesn't work on Xiaomi phones, Motorola and pixel phones working fine, any ideas on how to change the refresh rate on Xiaomi phones?

Link to the official framerate doc: https://developer.android.com/media/optimize/performance/frame-rate

I guess it has something to do with MIUI, but I'm not sure.

Any help would be appreciated!

Thanks

10 Comments
2024/11/30
23:29 UTC

82

Optimizing Bytecode: Surprising Performance Gains

As a side project, I’ve been experimenting with bytecode optimization and achieved some intriguing results:

🚀 3x speedup in Android’s presentation layer
30% faster startup times for Uber

These are proof-of-concept results, but the potential feels significant. If there’s interest, I’d be happy to release the code, explore further, and explore these techniques further.

I know tools like Redex, baseline profiles, and Dexguard/R8. They operate at a different level and these results suggest there’s still a lot of potential.

Why aren’t these kinds of optimizations more common? I’d love to hear your thoughts or collaborate to push this further!

📄 Full blog post with video and graphs here

21 Comments
2024/11/29
18:56 UTC

53

[Update] Over 200+ Jetpack Compose/Compose Multiplatform libraries submitted to ComposeLibraries.com

1 Comment
2024/11/29
14:30 UTC

55

I created a small Android Studio plugin that creates previews from your composable

I created a small Android Studio plugin that creates previews from you composable function. It's quite simple so far. When you cursor is on a top level composable function name you can find "Create Composable Preview" in the generate menu (control + enter). It then takes the name of the composable function and creates a preview function with a suffix you can set in the settings. It also initializes all parameters of you composable and adds an import for the preview annotation if there is none.

You can find it here:
https://plugins.jetbrains.com/plugin/25951-jetpack-compose-preview-creator/

and the code on github: https://github.com/EarlOfEgo/Jetpack-Compose-preview-creator

https://i.redd.it/c1bc017dju3e1.gif

11 Comments
2024/11/29
14:03 UTC

16

Handling secrets

Hello Everyone!

I am working on a project and I am trying to find the best way to securely store and handle secret keys (like secretEncryptKey, AWSKeys, etc.) without exposing them in code. I am looking for solutions that do not include:

  • Hardcoding the secrets directly in the code.
  • Using Firebase or similar services to fetch the keys.
  • Storing secrets in the build.gradle file.
  • Relying on.gitignore to prevent keys from being tracked by version control.

I am seeking some secure and scalable ways of handling secrets—be it a third-party service, encryption methods, or a secure storage solution that integrates well with the project. Any suggestions or best practices would be much appreciated!

Thanks in advance for your insights!

18 Comments
2024/11/29
08:06 UTC

256

I made an open-source wiki App built with Compose Multiplatform! (Figma & GitHub)

31 Comments
2024/11/29
01:15 UTC

27

Kotlin multiple declarations in one file

I am working on a project and have a very small interface and a class that implements it. I placed them in the same file as I think it's not really necessary to split them into two separate files because of their size.

In the Kotlin coding conventions page it's encouraged to place multiple declarations in a single file as long as they are closely related to each other. Although it states that in particular for extension functions.

I was suggested to split them into separate files. So, what would the best practice be here ?

67 Comments
2024/11/28
17:52 UTC

16

Open-Source Android Library — WYSIWYG Rich Editor for Jetpack Compose

Hello Android devs! 👋

We've just released an open-source WYSIWYG Rich Editor for Jetpack Compose that makes adding rich text editing to your Android apps easier and more fun than ever!

If you've ever wanted to seamlessly integrate rich text features like bold, italic, underline, and different heading levels into your Jetpack Compose applications, this editor is for you!

Key Features

  • Bold, Italic, and Underline Formatting — Easily apply bold, italic, or underline styles to your text, enhancing the user experience with just a tap.

  • Multiple Heading Levels — Organize content effectively with support for various heading sizes, perfect for note-taking apps, blogs, or any text-rich application.

  • User-Friendly Interface — An intuitive UI that makes text editing straightforward for users of all levels.

  • Seamless Integration with Jetpack Compose — Designed specifically for Jetpack Compose, so you can integrate it effortlessly into your existing projects.

Why Use It?

  • Easy to Implement — Get up and running quickly with straightforward documentation and examples.

  • Customizable — Tailor the editor to fit your app's design and functionality needs.

  • Open Source — It's open for contributions! Help us improve by submitting issues or pull requests.

Give It a Try and Share Your Thoughts!

If you're looking to enhance your app with rich text editing capabilities, give it a shot and let us know what you think! We'd love to hear your feedback or any contributions you want to make.

👉 GitHub Repository: https://github.com/canopas/rich-editor-compose

2 Comments
2024/11/28
05:06 UTC

0

How Are Permissions Handled After Accepting

Hi, i'm an iOS Developer that is developing on an Android application. Before using the app, the user must individually turn on permissions on each platform. In iOS, if a certain permission is turned off either through the OS Settings app, or from swiping down on the screen, then we use an OS popup/message that the user can either press close or press Settings, and go to the OS Settings. How is this handled on Android applications? Do you do the same thing or do you go back to the permissions like you did on first use?

3 Comments
2024/11/27
20:13 UTC

250

App incorrectly labeled as malware -> lost 30,000+ users -> embassy intervened

Hi fellow developers,

I hope this post complies with the sub's rules, otherwise, mods, feel free to remove it if it doesn’t add value. Still, I believe the story is worth sharing.

I’m an Android developer, and published an app a few years ago. Today, I work on it full-time. It’s not making me rich, but it’s enough to live a happy live. I couldn’t be happier!

Last week, however, disaster struck. One of the major Chinese phone manufacturers began flagging my app as malware, falsely claiming it steals payment information and leaks data. Their system even displayed a pop-up urging and allowing users to delete the app.

Obviously, these accusations were baseless, but the damage was immediate—my app started losing over 5,000 users per day. I discovered this only through numerous negative user reviews.

I reached out to the manufacturer through every channel I could think of: emails to their security team, developer support, global support and national support teams, phone calls to the local support service, social media,... Days passed, but no response from anyone, except for one support representative who forwarded my complaint to their global support team. Meanwhile, the app continued loosing 5,000 users daily. I was desperate!

Luckily I contacted the commercial chamber in my country, an organization which represents all businesses in my country (a relatively small country). Though the staff there didn’t know much about how to help me, they suggested reaching out to their representative in Beijing, which I did.

What I didn’t realize at the time was that I had essentially contacted my country’s embassy in China! To my surprise, they responded immediately. They forwarded my complaint to the local consul, who then reached out to the manufacturer with an official email and personally called the vice president of the company.

Within a few hours, the warning was removed, and the user losses stopped.

I was absolutely amazed, not only by how quickly the situation was resolved but also by the dedication of my country’s representatives. I was so excited on how they supported a small business like mine.

The aftermath:
In just eight days, my app lost over 30,000 users due to this incorrect notification. My review section has now multiple negative reviews accusing my app of being a virus. To date, I haven’t received any direct communication from the manufacturer on the resolution of this issue. While I’ve considered pursuing damages, I doubt there’s any real chance of success against a company based in China, and with this size.

Anyway, it was an exciting experience. Even when you do everything right, bad things will happen. So be persistent, explore every option, and ask for help wherever you can.

So, if you ever find yourself being treated unfairly by large corporations, reach out to involve local authorities or business organizations. Even as a small business, you’re a valuable part of your country’s economy, and they will stand with you.

Final thought:
Is your life too boring? Become an indie developer!

EDIT: while it was a Chinese manufacturer, its devices are used globally, so I was loosing users all around the globe.

39 Comments
2024/11/27
13:58 UTC

Back To Top