T O P

Weekly Questions Thread - June 01, 2021

Weekly Questions Thread - June 01, 2021

WhatYallGonnaDO

I'm using navigation with safe args and it's working well except for a single action. The action is generated with another in the same Direction file but only the second one can be seen. If I use the first one I get "Unresolved Reference" BUT it works when I call it. It wouldn't be a problem but I've seen a couple of crashed in the console related to it. public class TorrentDetailsFragmentDirections private constructor() { ... public companion object { public fun actionTorrentDetailsToTorrentFolder(folder: String?, torrent: TorrentItem?): NavDirections = ActionTorrentDetailsToTorrentFolder(folder, torrent) public fun actionTorrentDetailsToDownloadDetailsDest(details: DownloadItem): NavDirections = ActionTorrentDetailsToDownloadDetailsDest(details) } } called using override fun onDownloadClick(item: TorrentItem) { if (item.links.size > 1) { val action = TorrentDetailsFragmentDirections.actionTorrentDetailsToTorrentFolder( folder = null, torrent = item ) findNavController().navigate(action) } else { viewModel.downloadTorrent() } } `actionTorrentDetailsToTorrentFolder` is not recognized, anybody encountered something similar? Already tried changing AS, invalidating etc. The play console shows this exception that I never encountered myself java.lang.IllegalArgumentException: at androidx.navigation.NavController.navigate (NavController.java) at androidx.navigation.NavController.navigate (NavController.java) at androidx.navigation.NavController.navigate (NavController.java) at androidx.navigation.NavController.navigate (NavController.java) at com.github.livingwithhippos.unchained.torrentdetails.view.TorrentDetailsFragment.onDownloadClick (TorrentDetailsFragment.java) at com.github.livingwithhippos.unchained.databinding.FragmentTorrentDetailsBindingImpl._internalCallbackOnClick (FragmentTorrentDetailsBindingImpl.java:11) at com.github.livingwithhippos.unchained.generated.callback.OnClickListener.onClick (OnClickListener.java:4) Edit: I solved it, I have multiple navigation files for my bottom bar and two of them had the same fragment but not that action


yaaaaayPancakes

Is there any effective difference between `ProcessLifecycleOwner.get().lifecycleScope` and `MainScope()`? Wondering what the best scope is to use to scope things to the Application lifecycle.


i_like_chicken_69

Can anyone help out please How to parse HTML inside an string object using GSON? https://stackoverflow.com/questions/67870307/how-to-parse-html-inside-an-string-object-using-gson


f1r4tc

Hi, Google says getExternalStorageDirectory is deprecated and shouldn't be used. [https://developer.android.com/reference/android/os/Environment#getExternalStorageDirectory()](https://developer.android.com/reference/android/os/Environment#getExternalStorageDirectory()) I can use getExternalFilesDir() but this directory is not directory accessible for the users, starting from Android R. How am I suppose to save a file and expect that the user can access the file via a file manager app? What am I missing here? I don't want to implement some inconsistent behavior across different kinds of devices or APIs.


KP_2016

[Fuck storage access framework](https://github.com/K1rakishou/Fuck-Storage-Access-Framework).


Fransiscu

hey, i've been trying to implement a very simple quick tile for my app and failed doing so. I ended up following a youtube tutorial which works in theory but not in actuality my manifest: my java file package com.frans.piapp.service; import android.content.Intent; import android.graphics.drawable.Icon; import android.os.Build; import android.os.IBinder; import android.service.quicksettings.Tile; import android.service.quicksettings.TileService; import android.util.Log; import androidx.annotation.RequiresApi; import com.frans.piapp.R; @RequiresApi(api = Build.VERSION_CODES.N) public class DoNotDisturbTileService extends TileService { private final int STATE_ON = 1; private final int STATE_OFF = 0; private int toggle = STATE_ON; @Override public void onDestroy() { super.onDestroy(); } @Override public void onTileRemoved() { super.onTileRemoved(); } @Override public void onStopListening() { super.onStopListening(); } @Override public IBinder onBind(Intent intent) { return super.onBind(intent); } public DoNotDisturbTileService() { super(); } @Override public void onTileAdded() { super.onTileAdded(); } @Override public void onStartListening() { super.onStartListening(); Tile myTile = getQsTile(); Log.d("test", "start listening tile"); } @Override public void onClick() { super.onClick(); Icon icon; if (toggle == STATE_ON) { toggle = STATE_OFF; icon = Icon.createWithResource(getApplicationContext(), R.drawable.pi_dnd); } else { toggle = STATE_ON; icon = Icon.createWithResource(getApplicationContext(), R.drawable.pi_dnd); } getQsTile().setIcon(icon); getQsTile().updateTile(); } } the quick tile never appears and i cannot find it anywhere


MaHcIn

My Android emulators in Android Studio (4.2.1) stopped working altogether. I can launch them, and the \`qemu-system-x86\_64\` process appears immediately, but nothing else happens. No emulator window or anything. I've tried everything (reinstalling AS, restarting my mac...) to no avail.


TheRenegadeKaladian

I have the same problem and have not found any fix yet


MaHcIn

I just downloaded Android Studio Beta build and installed it alongside the stable build. It works, the emulator launches. I guess I'll be using Beta build whenever I need an emulator until it's fixed on the production build.


SuddenAstronaut

How do you preview landscape layouts in Jetpack compose? I cant seem to get the preview to rotate 90 degrees


tgo1014

Just add a custom width and height in the preview @Preview(widthDp = 800, heightDp = 400)


DivingBoots

Thats not exactly the same thing... For instance, if you're using `LocalConfiguration.current.orientation` to check for the orientation, the compose preview will still show the vertical composable, but in a landscape view. That being said, if you provide the orientation as a parameter to the composable, then you can preview it like you've said.


FullAbsurd

My app has a global timer that logs the user out when the time runs out and goes to the login screen. If the user is on another app, my app comes to the foreground whenever the automatic logout process occur. Any idea on what might be happening?


Zhuinden

Enqueue the action to run only after onStart


itpgsi2

I assume your timer code starts login activity, so it comes on screen, what else do you expect? Activity start is a system-wide action, the same as if user taps launcher icon. Also, recent Android versions (10 and up I believe, API 29+) specifically prohibit this behavior - starting of Activity from background app/service. Did you test it on recent versions?


FullAbsurd

Looks like this is happening only in android < 10. The client asked that the app didn't came on screen when the user is logged out, but it seems that it's not possible.


DotX21

Will 14 or 15.6" laptop be better? I'm going to study IT, so I need alight laptop with good battery life. I will be using it for Android devas well. I've decided to go with HP ProBook/EliteBook series with RyzenCPU. Only thing I'm not sure about is display size. I've compared 14"and 15.6" laptops at the local store, and 15.6" is much more comfortableto my eyes. It doesn't strain them as much as 14". But 14" laptops areligher, smaller, and IMO look better. Battery life should be a littlebit better with 14" as well. What are your toughts on that? Is 14"screen good enough for some programming?


SuddenAstronaut

While programming is easily done on a 14" screen, I personally prefer the 15.6" screens due to less eye strain. Eye health is a very important consideration, especially when you'll be working on your computer for over 8 hours a day.


DotX21

Considering that I need a laptop for university as well, form factor is important. However I've been at store today and compared 14" and 15.6". Yes, 14" laptop is much more portable, but I felt kind of tired while looking at its screen. Idk maybe I need to gest used to smaller screen, but surely 15.6" is more convenient when it comes to working. On the other hand form factor of 14" laptop is just better. Do you have any recommendation on light 15.6" laptop with good battery life? I only found HP EliteBook 855 G7 meet my needs. It might have dGPU as long as battery life is good (at least 9-10h of light tasks)


Symkach

I'm comfortable with 15"6, but only with tiling wm, anything smaller is unusable, imo


DotX21

Does tiling wm make such a huge difference? Yeah I find 15.6" more comfortable when it comes to work too. I need a laptop for university tho. That's why form factor matters as well. That's a tough choice. Do you have any recommendation on light 15.6" laptop with good battery life? dGPU would be a nice addition but it is not necessary. I prefer good battery life over dGPU.


Symkach

I would say tiling + workspaces, though you can use them in stacked wm too. I use no more than 2 windows per workspace, with exception of terminals, and just bind essential apps to workspaces, i.e. when I receive slack notification, I always know that slack is on fourth workspace, so I instantly switch to it with mod + 4 shortcut. Same goes for Android Studio, Android Emulator, Browser and player I wouldn't say difference is huge but I defenitely feel myself more productive with tiling wm. And I switching back and forth to desktop environments with stacked wm(kde or gnome), cause they look better. So it's just a choice towards productivity or aesthetics I do not have recommendations, but can say a bit about my experience. I'm not rich, so i bought one of a budget gaming laptop, hp pavilion, and I regret a bit, it has bad screen and thick frames. Now I would add extra cash for better screen quality. Take a look [here](https://www.reddit.com/r/LaptopDeals/comments/koe108/best_general_use_laptops_updated_for_january_2021/)


MKevin3

You are breaking Rule #7 - No hardware / software purchasing advice Honestly I don't know the best place to ask for this advice though.


DotX21

Thanks for pointing it out. Aren't specific questions regarding hardware allowed in weekly question thread? I mean I thought I can ask here. I wanted to ask people who have more experience with development, that's why I chose this place.


IntuitionaL

I want to get into learning how to do animations and transitions to really spice up my apps. As a total beginner, what is the easiest and most useful thing to learn for this? Motion layout? Transition manager? Object animators? As a beginner, I would really like automatic solutions such as the XML attribute `android:animateLayoutChanges` or frameworks which give me some default animations that I do not have to control myself.


LittleRedHendo

Beginner here, been trying to teach myself android since February. The first 2 months I was doing good old fashioned xml and activity style tutorials, but since then I've been doing almost only trying to learn jetpack Compose. How important do you think it is for me to learn Jetpack and making apps the regular fully supported way, or should I just keep trying to master Compose? I just eventually want to get a job anywhere working with Android, but some times it feels like I'm not gaining anything, or I'm learning the wrong things. Thanks in advance for any advice.


Zhuinden

> I just eventually want to get a job anywhere working with Android Then you're not looking for Jetpack Compose yet


LittleRedHendo

You're comment motivated me to go back through the Android fundamental codelabs, and developing without compose is a lot better than I remember! Thanks again for a sincere response. Here's a free award.


Zhuinden

Thanks 🤗


LittleRedHendo

Thank you so much for your response. Reading it now, it seems obvious, but LazyColumn are just too tempting I guess. I suppose I'll just have a head start if the transition ever happens to compose! Thanks!


jorjor1776

My Pixel 4a has been losing large amounts of charge everytime Chrome is used. Any suggestions for a fix? OS=Android 11 Stats: chrome usage time=11min, battery drain=12%


Superblazer

If it's just Chrome causing it, Chrome is a heavy browser, ads and trackers are known to use a lot of device resources. Switch to Brave or Firefox with extensions, both of which are open source and actually respect your privacy.


jorjor1776

Thanks! I switched to Firefox. I didn't used to have this issue though with Chrome, so I was curious if there is a known fix. Thanks again.


3dom

Anybody got experience with RevenueCat to manage subscriptions? Is it any good?


lawloretienne

I need to use different dimensions for different screen sizes. specifically i need different dimensions for a pixel 4xl vs. a Nexus 4.Which dimension resource directories do i need to differentiate small and large screen sizes?I tried with values-sw320dp/dimens.xml and values/dimens.xml but both devices are using the dimensions defined in the values-sw320dp/dimens.xml file.


lawloretienne

the issue is there is a sales page i am trying to implement and the main CTA (call to action) Subscribe button needs to appear above the fold. if i just use the dimensions defined in the design doc then that button is below the fold on a Nexus 4. however if i modify the dimensions than it will appear above the fold. it is important for this to be above the fold because it will lead to higher conversion rates.


itpgsi2

sw qualifier doesn't provide enough flexibility, in practice it WAS only used to differentiate phone/tablet, but at current time with foldables, abundance of large screens and user-controllable scaling, even this qualifier can be wrong. As for your use case, you can solve it in number of ways, for example: 1. Build your layout with percent constraints, such that every part of layout takes exactly n% of available height instead of fixed dp dimension. Most important widgets are left with wrap\_content, and for the rest of text content you can use auto-sized TextViews so it scales up/down for available dimension. You can set high threshold for text size, so it doesn't get too big on large screens. 2. Even easier: make CTA button sit at fixed position above your layout, constrained to bottom like Floating Action Button. Then just make your content scrollable by wrapping in (Nested)ScrollView. On smaller screen some content may end up under CTA, but that's not a problem, as user will be able to scroll (add enough padding to allow over-scrolling to compensate button overlap). 3. Make some parts of layout collapsible with default collapsed state as in Show more/less UI pattern.


Wispborne

Kotlin is deprecating support for Java 1.6, and by extension Java 7. Does this mean that Kotlin will not support Android 5, going forward?


itpgsi2

No. Java 8 is supported on any API level through desugaring. >If you're building your app using Android Gradle plugin 4.0.0 or higher, the plugin extends support for using a number of Java 8 language APIs without requiring a minimum API level for your app. https://developer.android.com/studio/write/java8-support


Sabboo0

I am trying to follow the feature per module pattern in modularization but I encounter this use case. I have viewpager and in its adapter I create two fragments but these two fragments are also been used independently (not inside viewpager) somewhere else so, I am trying to separate them to reuse them but then the adapter won't aceess these fragments. I am thinking of creating separate module to just hold adapter and it will depend on the two fragments module but then I would break the rule that state no feature module should depend on another feature module. Or this is not actually a feature module and it act as a helper. I don't know what are my potential go to approaches?


Zhuinden

writing a custom adapter that is capable of invoking a fragment factory even without knowing the exact fragment instances


Sabboo0

Sounds a perfect fit solution to me, Thanks dude 👌


BabaYaga141

I am a complete noob in android development and I want to learn android development the best possible way like without wasting my time (as I'm an undergrad student and have too much pressure on me with different courses, i can only learn the things i want in sem breaks which is like 2 weeks) on things that are like obsolete or nobody uses it that much. What would be the efficient way of learning android development in 2021where I can learn the best practices and everything along the way? There's this thing called android jetpack and jetpack compose which are very modern in android development, should I start from there? Any suggestions would be absolutely appreciated. Thanks!


Zhuinden

> jetpack compose Jetpack Compose is beta and not stable yet, there are also barely any resources, and many existing resources aren't up to date as they were made for previous beta versions or even alpha versions


BabaYaga141

Then what are your suggestions for ui design? what alternative is there for jetpack compose?


Zhuinden

the layout XML that has been there and worked since API 1


3dom

Google has decent set of articles / tutorials (StackOverflow answers and Medium articles have obsolete stuff more often than not). Side column in this sub has this section: > New Developer Resources Start with the "[Build your first app](https://developer.android.com/training/basics/firstapp)" link. Once you'll be able to launch the app on a device or emulator - iterate the app by adding buttons, reactions, user input fields, save this data between screen rotations and app launches. Likely you'll need Jetpack ViewModels. Then add multiple screens (Jetpack Navigation). Then Room database. If you'll be able to do all of these, then repeat it in couple other apps (see "App Portfolio Ideas, Tiered List" link) - you are practically a capable developer.


BabaYaga141

Thank you !


sudhirkhanger

Do you use runBlocking.launch { // some db call like clearing table } in production code outside tests? Or would something like following will be better. lifecycleScope.launch { // db call super.onDestroy() } One problem I am expecting is that due to some reason call to super.onDestroy() may not be made from the launch coroutine. Or maybe the call is never finished because the scope is cancelled. Maybe I can wrap db call in a try catch block with cancellation exception where I do super.onDestroy().


Zhuinden

withContext(NonCancellable) or run it in a superscope i guess


[deleted]

[удалено]


sudhirkhanger

The idea was to clear the db from something like BaseActivity so that the data is wiped when all Activities have been destroyed. And to not leave this to be implemented per Activity or ViewModel where future devs might not know if they have to do that.