Android Development

0 readers
1 users here now

Welcome to the programming.dev Android development community!

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License

founded 2 years ago
MODERATORS
1
 
 

Hi guys.

I have an android head unit for my car that only manages multimedia, navigation and stuff. it also has multiple physical buttons and knobs. It’s offbrand so can name the particular brand or model.

can I for example upgrade the OS?

2
 
 

Hi everyone,

As I've been developing my Android app, I've quickly found myself in a situation, where all my @Composable functions are quite hectic, not really maintainable.

I am wondering, is there any guide for best practices regarding @Composable functions?

Thinking in Compose is a straightforward article, and it all makes sense - until I want to build something other than Hello World. Something more complex, I mean.

What I understand from the article is, that I should keep the logic out of these functions as much as possible, and pass only primitive types as parameters. Behavior should be kept in callback functions. This is very nice and clean, I like it, but then what should I do, when I have quite a lot of functions nested?

For example, on MainActivity I have a Scaffold, within that a NavHost with four different tabs, each with completely different content, some of them with a BottomSheet, which are also completely different for each tab (that has one), and some of the BottomSheets can call a Dialog, which again, has a form in it, and so on. So the hierarchy has quite a level of nesting. And if I understand the recommendation correctly from the article mentioned above, then I am supposed to keep the states and callback function definitions somewhere in MainActivity (or ViewModel), and pass everything through the entire hierarchy. Everything. The value of every single Text (those that cannot be hardcoded), all the list items to DropdownMenus, all the list items for Lists, literally everything. And then, according to the article, the renderer is smart enough to only recompose those elements that really changed.

To me this sounds tedious. I've also seen recommendations to just pass the ViewModel itself in order to reduce the number of parameters. But if I do that, then how would I make a @Preview out of it? Probably it's possible, but it wouldn't be convenient at all.

So what's a clean approach for designing a good @Composable function hierarchy?

3
 
 

I'm looking for something that goes through building a jetpack compose app with storage.

I find linking the UI state with data updates really confusing. I can get it to show up, but updates are inconsistent/jumpy.

I've been working on a project where the source of truth for the data is actually coming over a Bluetooth connection, and my code feels like a mess. I want to see what good code looks like from scratch so I see what parts of my code are salvageable.

4
5
6
7
8
 
 

I'm a very results oriented person. Doing shit for arbitrary numbers in class? Doesn't do anything for me, they're just numbers. However making something that I actually find useful will get me going. I used to take comp sci classes and know Java, even made a few shitty apps for class back in the day. However, I had a hard time sticking with it because we weren't really learning anything to make it immediately valuable. Could dick around in Php for weeks trying to build a website, but cannot focus for classes.

Anyways, my idea is to port PKHex, a popular open source Pokemon save editor. Someone made a port a few years ago, but it doesn't work with anything past Android 11, hasn't been updated in 2 years, and the dev expects you to build the app yourself. So making a new version for Android seems very interesting to me. Is it a good idea for a first 'big' project?

9
10
11
12
 
 

There is probably something like this already, but probably not free and open source, as quick search through F-Droid did not show it.

A fitness app where you place your phone under your face and it counts how many push ups you did.
What would be the best way to detect a push-up?
My idea is to have user touch the touchscreen with their nose. That would initiate the first part.
Second part would be more complex: use the front-facing camera to figure out if user's face is far enough to be considered a completed push-up. User would have to calibrate the app at the start, or maybe even at the start of each session, indicating how far away is the max height that they achieve. Probably no need for full facial recognition for this, some colour-matching algorithm should be enough. And use phone's gyro to check whether phone is actually in a horisontal position.

Maybe this idea has enough potential to actually get a project going.

13
1
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

I am trying to convert a view based screen to Compose and while what I need should be very basic, somehow I can't get this to work. The use case at hand is a serial task where one step follows the other and the UI should reflect progress. But I seem to miss something fundamental because none of my Text() will update. Below is a simplified example of what I got:

    override fun onCreate(savedInstanceState: Bundle?) {
        …
        
        setContent {
            Import()
        }
    }
    
    
    @Composable
    fun Import() {        
        var step1 by remember { mutableStateOf("") }
        var step2 by remember { mutableStateOf("") }
          
        Column() {
                Text(text = step1)
                Text(text = step2)
            }
        }

        step1 = "Open ZIP file"
        val zipIn: ZipInputStream = openZIPFile()
        step1 = "✓ $step1"
    
        step2 = "Extract files"
        val count = extractFiles()
        step2 = "✓ $step2"
        …
    }

If I set the initial text in the remember line, like this

var step1 by remember { mutableStateOf("Open ZIP file") }

the text will show, but also never gets updated.

I also tried to move the logic part into a separate function which gets executed right after setContent() but then the step1/step2 aren't available for me to update.

#######

Edit:

Well, as expected this turned out to be really easy. I have to break this one

var step1 by remember { mutableStateOf("Open ZIP file") }

into 2 statements:

var step1String =  mutableStateOf("Open ZIP file")

With step1String as a class wide variable so I can change it from other functions. In the Import() composable function al I need is this:

var step1 by remember { step1String }

Have to say Compose is growing on me… :-)

14
 
 

I'm new (0 experience) to Android Dev, but want to contribute to one simple open-source app that I like on GitHub.

I had a spare hour today and tried to setup GitHub Codespaces environment, but so far failed to install AndroidSDK and satisfy Gradle.

So the question, what setups do you have for Android dev? What's industry standard and what YOU prefer?

And is cloud development a thing in Android world?

15
 
 

Y-Charts is a Jetpack Compose-based charts/graphs library that enables developers to easily integrate various types of charts/graphs into their existing UI to visually represent statistical data.

16
 
 

Hey, I have a function that draws a composable,

@Composable
        fun home() : @Composable RowScope.() -> Unit {
            return {
                BottomNavigationItem(
                    icon = {
                        Icon(Icons.Filled.Home, "Home")
                    },
                    onClick = {},
                    selected = false,
                    label = {
                        Text("Home")
                    }
                )
            }
        }

That doesn't draw it to the GUI I am calling it with

@Composable
fun App() {
    MaterialTheme {
        BottomAppBar {
            StaticAssets.BarButtons.home()
        }
    }
}

Does anyone know why it doesn't work?

17
18
 
 

Possibly a stupid question, but how do I add functionality to the back button in Android without reimplementing the back button entirely nowadays?

Prior to last year, I would just call onBackPressed() and then simply override it:

override fun onBackPressed() {
	super.onBackPressed()

	doMyStuff()
}

It looks like this is now deprecated, and it's recommended to use OnBackPressedCallback objects. It's simple enough to replace onBackPressed() with onBackPressedDispatcher.onBackPressed(), but I can't figure out how to recreate the override.

I can replace the functionality easy enough:

override fun onCreate(savedInstanceState: Bundle?) {
	super.onCreate(savedInstanceState)
	…
	onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
		doMyStuff()
	})
}

However, this replaces all back button behavior. It doesn't just add to it, despite the function name. I still want the back button to go back, but don't want to have to try to reinvent the wheel. Is there some equivalent to super.onBackPressed() with this new API or another way to achieve this?

19
 
 

Title. Looks like a really interesting plugin, has anybody had any experience using it in production?

20
 
 

The Kotlin type system is amazingly designed. Many features that look like special cases are just a natural consequence of how the type system is designed.

21
1
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

Feedback and criticism is welcome and encouraged!

This is a small jetpack compose app that I'm currently making for android devices to browse... federated link agregators (Lemmy, kbin etc.).

I promise I'm not just bandwagon-ing. However, I thought that the current situation could make for a good excuse to learn android development/mobile design (something I've never actually done before).

Some notes:

  • This application will be open source. I think it's just a bit too early to share it right now. [^1]
  • Some icons are placeholders, e.g. "upvote" and "downvote" are upload and download at the minute.
  • Some of the padding and card-style is inconsistent in the mockups I've shared here.
  • There are quite a few "language-choice" issues. Most notably the vague term "Mods" on the profile page (this refers to the communities the profile moderates). I plan to adjust this through development (and as the mainstream fediverse establishes itself).
  • I'm doing this for selfish reasons like "fun" and "education", so there aren't any guarantees for a fully working... anything...
    • If I was to do this for altruistic reasons, I'd contribute to Jerboa which seems to be undergoing a lot of development from what I can tell on GitHub,

[^1]: If you're on the tildeverse, I've already open-sourced it to tildegit. I'm also tracking my progress over there: https://tildegit.org/delph.seiji/lemulink.

22
 
 

With more people hopefully coming over from Reddit, I wanted to give some visibility to Jerboa. This is an Android app for Lemmy, written in Compose.