T O P

Weekly Questions Thread - June 15, 2021

Weekly Questions Thread - June 15, 2021

starygrzejnik

Like month ago I found here interesting article on Medium about comparison mobile apps market vs pc, but now I can't find it, maybe someone can help.


sudhirkhanger

adb shell am kill com.example.android.architecture.blueprints.master.mock This command doesn't seem to kill the process. I have tried `--user all` and `--user current` with no luck.


sudhirkhanger

adb shell ps -A | grep lifecycle Is the keyword `lifecycle` supposed to tell me anything?


layfox

Hello, I just want to know if my project is possible to do on android: With friends we're making Formula 1 bet on a shared excel sheet (I made a excel sheet with automatic calculations points, etc), but we keep having problems with shared files (we don't all have the same data, some cases get crazy etc) so i wanted to try making it an app. So basically, want i would like to do is: Create/join "rooms" (room n° + pswrd) => Create/select a user (You) and then being able to edit your prognostics . At the end of the journey, the one who create the room can input the true results and everything get calculated, etc. I think the calculation part should be fine, but i don't know if it is possible to make "rooms" + pswrd and users and having a shared database that be permanently updating for everyone as each of us add his prognostics. If yes, any video recommendation about those aspects ? Thanks ! (I already code a bit with python using .json as "database". )


3dom

How to close AlertDialogs from activity in Jetpack Navigation? This construct ignores them completely somehow: private fun rewindScreens() { val navController = findNavController(R.id.nav_host_fragment) val cfm = supportFragmentManager. findFragmentById(R.id.nav_host_fragment)?. childFragmentManager if (cfm?.backStackEntryCount!! > 0) { cfm.getBackStackEntryAt(0).name?.also { if (cfm.findFragmentByTag(it) is ContactsFragment?) { navController.popBackStack(R.id.screenMain, false) } } } } ContactsFragment = start screen fragment a.k.a. R.id.screenMain destination. navController.navigate(R.id.screenMain, null, NavOptions.Builder().setPopUpTo(navController.graph.startDestination, true).build()) doesn't close them either. Edit: replaced the whole thing with the basic private fun rewindScreens() { findNavController(R.id.nav_host_fragment).popBackStack(R.id.screenMain, false) } but AlertDialogs aren't affected at all. Still hanging there after rewind.


Zhuinden

Are you sure that calling Activity.onBackPressed won't do the correct thing? 🤔


3dom

I've tried it and it's unreliable (cascading defects and errors). Could be nice to have SDK method to check if there is an AlertDialog hanging out on the screen?


itpgsi2

I don't follow this code to be honest. NavController operates `supportFragmentManager` and here we see `childFragmentManager`mixed in for mysterious reason. How `cfm?.backStackEntryCount!! > 0` condition can be ever satisfied? Even if DialogFragment is specifically added to child FM via manual transaction, this doesn't increment backstack count, it stays at zero. And you should NOT be doing it manually if you use Navigation lib, it supports DialogFragment destinations as well via `

` tag. >`cfm.findFragmentByTag(it) is ContactsFragment?` That's totally not how you check backstack destination with Navigation lib. Here: `navController.currentBackStackEntry?.destination.id == R.id.contactsFragment`


3dom

Why thank you for the code review! It doesn't help with the removal of AlertDialogs though.


itpgsi2

DialogFragment can be a container for AlertDialog too. DialogFragment is just a thin wrapper to make Dialogs manageable by FragmentManager (perk is free state management - preserve visibility on screen rotation/config change). Dialog is created in onCreateDialog without any restrictions, I even put ProgressDialog in a DialogFragment. While we're at it, I must also note that you should always prefer AppCompat subclasses for theme consistency: AppCompatDialogFragment, androidx.appcompat.app.AlertDialog or even MaterialAlertDialogBuilder (if you use Material Components and derive from Theme.MaterialComponents.\*)


3dom

Thanks for the note! The problem with the alerts - some of them are produced by libraries I can't control. Or at least they are not that easy to control.


aperture_synce

Hm, what exactly creates the alert dialog? Why are you trying to close it from the activity? Is this in response to some other event like a network request?


3dom

Fragments create dialogs. Activity has centralized backstack rewind operation. Currently it's a response to widget click. In other cases it's a reaction to user's logout.


aperture_synce

Hm, you could just make the dialogs a destination of the navigation components, and that way you should be able to pop it all out with less fanfare. Let me go back and see the code again. Edit: When you create the dialogs, are you using DialogFragment? Are you using the Jetpack version or the Android SDK version? Also, are you using the Activity fragment manager, or the child fragment manager of the fragment that's showing the dialog?


3dom

There are libraries which create AlertDialogs which can't be dismissed like fragment variants, via backstack. I've ended up rewriting them. Felt like it's 2015 again - with Eclipse instead of AS (since I won't be able to renew their versions from Gradle).


aperture_synce

Hm, I see. Yeah, libraries don't always provide the kind of control you need.


hunnihundert

I am soon starting my first Android dev job at a start up (used to be part of a bigger company but the department has been spun off as a start up, so the people there have mostly been working at the same company, size of the start up is approx 30~40). I have zero experience and am self taught, i signed my contract in feb but due to different reasons my first day will be july 1st. Meanwhile we (the team I will be working: 1 experienced dev, 1 dev with 1~2 year experience) have been having a video conference once a month and just talked very casually to get to know each other. The chemical seems to fit luckily :). I am very thankful for the job and for them taking their time to videocall me, despite that I am really looking forward to finally start as a professionell dev after years of studying. My question is: how can I become the most helpful, least annoying newbie? What can I do to speed up the boarding process? What should I avoid doing? I am willing to put extra hours, actually I want to as I definitely have a not so stable foundation due to being self taught. Any comments are appreciated. Thank you very much!


aperture_synce

I'd say keep learning every day. Focus on some areas and improve your skills and knowledge there. For example, focus on writing good quality code i.e follow SOLID principles, learn how to write concurrent code properly, focus on Kotlin, learn how to deal with activity/fragment lifecycle, other Android components, how to structure your UI better, implement animations, deal with memory leaks, unnecessary CPU usage, reduce battery usage by your app etc. Watch anything useful in the Android Developers YouTube channel, see the blog posts on Android Dev Googleblog and their Medium page. Look for new and interesting libraries that you can use, that can make development easier and improve productivity (sometimes your seniors may not do this and they may just do NIH).


itpgsi2

>the most helpful, least annoying newbie The team will appreciate if a newbie asks a lot of questions to get on the same page instead of trying to not annoy anyone. It's the first priority to familiarize yourself with code practices and project flow that the team is accustomed to, and you just can't silently "reverse engineer" all of this. In the right perspective, questions are not annoying, what is actually annoying is checking in with a team member after a week spent on a task, and seeing that they got something wrong and the task must be redone. Also I would advise against putting in extra hours. In the long run I believe it contributes more to burnout, rather than to skill progression. My rule of thumb is to only put extra hours for work that is precisely timed (for example, making UI layouts when you get the hang of it), but NOT for research, implementation of complex business logic, or debug tasks, because these will consume any amount of time you throw in without guaranteed return. Sometimes taking a break and a fresh look helps more in problem solving than putting in extra hours. Also, to write good code fluently, you need to read a lot of good code from production apps, not just documentation snippets.


kevthedev12

I'm using Single-Activity Fragment architecture in my app with Firestore. I have a Helper class as a Singleton. It fetches all the information from the Firestore collection and uses a listener to call back to the MainActivity, which in turn passes that data to the Fragment for its Adapter. For some reason, my listener in my Helper method for Firebase is null, even though I have implemented it and its methods in my MainActivity. Any suggestions on why this could be happening?


Zhuinden

> I have a Helper class as a Singleton sus > For some reason, my listener in my Helper method for Firebase is null, even though I have implemented it and its methods in my MainActivity. Any suggestions on why this could be happening? Because you don't actually register a listener I guess


ofjsbwr

Can apps in the early access program charge money or have IAP?


curious_practice

Would any of you know or recommend self hosted, open source Android MDM? For a few thousand devices running Android 8 & 9 Need to be able to do single app kiosk, remote control, app lifecycle management, reboot, remote script execution etc. Thank you for ideas.


veDweN

Which combination of Android Studio version and Emulator API level are currently working on the Apple M1 processor? I had a working setup last month, but now I can't get any emulator to work correctly anymore on Arctic Fox Beta 3/4. API level 30 (R) emulators have internet, but chrome crashes immediately when opened and my app can't connect properly to the server either. API S (which used to work just a week or two ago) doesn't have any internet connection, with the WiFi turned off (and can't be turned on either, nothing happens when trying). Both output an endless log of errors into logcat while running, which makes it quite hard to pin the issue down. Any ideas? ​ edit: In case anyone finds this in the future: The new emulator version (30.7.4) seems to have fixed the issues. I see some posts saying it broke things for other people though, so do your research before upgrading blindly.


aperture_synce

Yeahhh....... it's best to wait until they declare it stable or atleast Beta or RC. Better to use stable software that works so you can focus on development. Maybe you can try out the x86 versions?


veDweN

I tried the stable x86 version first, but on there none of the emulators worked at all, which is why I have been using the beta versions for the past few weeks. From reading some posts around here there seem to be quite a few people already using apple silicon versions successfully, so I was hoping that there is at least one combination that works. On second thought, I should probably make a thread about it instead, might get more traction.


aperture_synce

Yeah, and also if you find a version that's stable, just stick to it and don't change until an actual stable release is made. M1 support is very new, don't depend on it for production use in any way, until Google declares it's stable (which will probably take months).


veDweN

That's good advice, yes. I should have kept the one that was working. I did the upgrade because it had some other issue, but in hindsight keeping it would have been better.


TheSenegalese

Hello I try to setup my own small lab for testing apps for some university project. I run into problems left and right for weeks now so I decided to ask here. I used https://github.com/ct-Open-Source/ctraspion to get my hand on network traffic of apps, installing mitmproxy certificate - I got problems with some apps tho, or more apk bundles I think. Can I decompile them so I can install a certificate? I found no really good answers to this yet. Also how should I go about using emulators? I used mobilesecurityframework and genymotion with it (cause it is recommended) I found a lot of stuff works on genymotion that does not on my rooted pixel I got my hands on and vice versa. Because I had problem installing some stuff on the pixel I wanted to connect the genymotion vm to the raspion wifi-accesspoint but no luck. Is that even possible? I am kinda lost right now, the task is to test apps dynamically and I for sure do not really know how to go about it, I tried so much and rarely succeeded, I also got real problems finding apps to test for example. If anyone can help with any of my problems that would be great.


Sabboo0

Regardless of the new navigation supporting multi stack updates as far as I understand its now automatically supported if you update the version when using `setupWithNavController` But what about the section that highlight saving views state away from BottomNavigationView. I found no examples of how the two new APIs are meant to be used.


Mavamaarten

Yeah, it's been quite poorly documented imo. I did find this when playing with it yesterday: https://developer.android.com/guide/navigation/navigation-navigate#savestate


Sabboo0

I think this is the missing part. I will try to implement and try it. Thanks for sharing this.


Mavamaarten

The weird thing to me is that there is no way of knowing if you can restore a certain backstack or not. RestoreBackstack does not return a boolean, nor can you look through the saved backstacks. I still gotta look through the bottom navigation bar code to see how they do it, but it seems weird that you'd have to keep this information somewhere yourself.


IntuitionaL

Is there a neat way to have an image within a TextView and have it wrap along with it and still be at the end of the text? [This is what I'm looking for.](https://i.stack.imgur.com/bgQSP.png) [But I'll usually get this.](https://i.stack.imgur.com/8lfwS.png) Using drawable end, or having an ImageView placed next to the TextView won't work.


aperture_synce

If it's a checkable thing (looks like a like button to me) , you could use Checkbox with a custom drawable for the checkbox. Otherwise,do what the other person said.


itpgsi2

[https://developer.android.com/reference/android/text/style/ImageSpan](https://developer.android.com/reference/android/text/style/ImageSpan) or https://developer.android.com/reference/android/text/style/DynamicDrawableSpan


BrokenAndDeadMoon

I tried to remount the emulator's filesystem in read-write but when i do so my emulator freezes and never reboots. I did: adb root adb remount -R And then it never reboots. Also in task manager it isnt using a lot of resources so it shouldnt be because it takes a lot of time since i dont have an pc good enough. Also when i used this command to run the emulator: emulator -avd MyAvd -writable-system -selinux permissive And when i used it with -verbose it dident say anything special when i used remount -R. Also if i clicked somewhere in the emulator screen it would say: emulator: VERBOSE: MultiDisplay.cpp:200: getMultiDisplay 0 x 0 y 0 w 1080 h 2220 dpi 0 flag 0 enable 1 emulator: VERBOSE: MultiDisplay.cpp:200: getMultiDisplay 0 x 0 y 0 w 1080 h 2220 dpi 0 flag 0 enable 1 And it every some secounds it would say: emulator: No acpi ini file provided, using default Anyone knows why i cant mount my partitions as read-write?


Mavamaarten

Which image did you use? I think you need a non-google-play image.


phileo99

I upgraded to Android Studio v4.2.1 and now my fonts in the Project view have shrunk in size. How can I adjust font size for only the Project view in Studio?


eldarium

Is there a straight forward way to "stick" one bitmap to another? I have two images - one ("back") that is displayed as a background and another ("stick") that the user drags around. "Back" is displayed with some scalings (match_parent on the image view), so there's actually 3 images in play. I need to apply "stick" to the third (original) image in the same position as it is displayed on the "back". I've tried to do it with matrices but had more luck manually calculating the offsets, yet it's still not enough as there's some weird offsets coming up and the "stick" is some pixels to the left. That's not even to say that it does not work if the image is more horizontal. [Here's how I calculate it](https://pastebin.com/pEu6W0Gv) Probably there's a library or a view for it?


Mavamaarten

Stupid question perhaps, but is it feasible to just do it with a view on top of the background? Moving a view around is very trivial.


eldarium

That's what I was doing already, the problem is that to apply that image in the exact position, with relative scaling, is harder than just applying matrix transformations. I figured how to do this in the end, just had to turn my brain on and subtract some margins. https://stackoverflow.com/a/68032958/4100174


pangolinportent

Hi all, has anyone managed to get Bluetooth working in an android emulator? I’d like to dev in an emulator but interacting with real BT devices


bart007345

BT is not supported.


pangolinportent

What would it take to support? I’m thinking Emulators are qemu under hood so passing a bt device seems possible if hard?


aperture_synce

Yeah, they just don't have support for it right now. Would be nice if they did.


bart007345

No idea. All I know is they don't.


[deleted]

[удалено]


3dom

This one is "a bit" different now. I have this construct for fragments: private val activityResultContactLink = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { // if (it.resultCode == Activity.RESULT_OK) { } it.data?.data?.let { addLinkedContact(it) } } private fun launchContactPicker() { val contactPickerIntent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI) activityResultContactLink.launch(contactPickerIntent) } Notice how you don't need onActivityResult() anymore. No idea how it works for multiple activities? edit: it seems the scheme is the same for activity. I didn't test it but the code compiles. Also you have [this link in SA comments](https://stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative) (and you've found it).


Afatinong

**Could not resolve com.android.tools.build:gradle:4.1.2 : Connection Reset** ​ **I am new to Android Studio, but when I try to create a new project. Gradle version 6.7.1 is installed well, but the Gradle plugin 4.2.0 is not, This error popup. I tried many things even VPN, turn off antivirus, and firewall. but I couldn't solve this problem. I post the error below.** ​ FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'My Application'. > Could not resolve all artifacts for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:4.2.1. Required by: project : > Could not resolve com.android.tools.build:gradle:4.2.1. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.pom'. > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.pom'. > Connection reset


bart007345

What happens when you go to https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.pom in your browser?


Afatinong

It downloads the file 'gradle-4.2.1.pom' size of 7kB. I tried it to check if my internet is working or not.


MKevin3

Are you using Fiddler or Charles Proxy? I have had to shut them down as well to get this to work. Both are network traffic sniffers.


Afatinong

I am not using any proxy, but once I tried VPN app. and I check the proxy setting. I set it to No Proxy.