|
I'm using retrofit2 with Jackson converter to communicate with a web service. One of the methods of this service accepts a POST request with a JSON object in its body. That JSON object must contain a JSON array of strings. On the client side this array is represented by an ArrayList<String>. Everything works fine when there are two or more strings in the list. However, if there is only one string in that list, it's serialized as a JSON object instead of a JSON array, which cannot be accepted by the web method. How to fix it? I am aware of SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, but, according to Jackson documentation, it's disabled by default. Providing a custom ObjectMapper with that feature explicitly disabled doesn't have any effect. Web method declaration: pre:@POST("api/FindByFilter") @FormUrlEncoded Call<BaseApiResponse<String>> findByFilter(@Field("Filter") List<String> filter); pre:Call<BaseApiResponse<String>> call = api.findByFilter(getFilter()); pre:{ "Filter" : [ "test" ] } pre:{ "Filter" : "test" } ringu0 fucked around with this message at 23:41 on Mar 11, 2019 |
# ? Mar 11, 2019 21:52 |
|
|
# ? May 23, 2024 17:07 |
Not too familiar with jackson's specifics but it sounds like you might be able to write a type converter that will place the object in a list of 1 or something like that. That's what I would do with logansquare or moshi
|
|
# ? Mar 11, 2019 22:09 |
|
Yeah, that's a possibility, I just think I'm missing something incredibly obvious in the way retrofit is set up or used. e: Ended up ditching individual parameters and their annotations and building the request body manually: Web method declaration: pre:@POST("api/FindByFilter") ringu0 fucked around with this message at 20:07 on Mar 12, 2019 |
# ? Mar 12, 2019 04:38 |
|
I'm an iOS developer just dipping my toes into Android development for the first time, but have hit some memory leaks on rotation. I've stripped my app back to the bare basics but I'm still seeing the leak (albeit smaller) in the profiler, and I'm not really sure which lifecycle events I'm missing where I presumably need some explicit cleanup. MainActivity: code:
code:
I don't have any pause/stop/destroyView methods implemented - is there anything here I need to explicitly destroy or disconnect to avoid leaks? Froist fucked around with this message at 22:55 on May 3, 2019 |
# ? May 3, 2019 22:32 |
|
code:
|
# ? May 3, 2019 22:54 |
|
Lutha Mahtin posted:
Sorry, I went back and heavily edited my post as I stripped all the ViewModel handling out and still saw the leak in a really minimal app. But to answer your question: I store my app's data objects (parsed JSON data from a server) within the ViewModel, and need to access this in a few different fragments - I omitted the others from my first post because I could repro the leak without ever loading those fragments. "vm" actually is used in my code later, as it takes a load of coordinates from those model objects and plots them on the map. It was my understanding (I may have this wrong!) that the ViewModel should be owned by the Activity (my app only has one) and looked up in each Fragment, as it's intended to have a lifecycle beyond that of any single fragment. Again I stripped all this ViewModel code out completely and the leak's still there, but if I'm doing something drastically wrong in the VM handling I'm happy to accept tips!
|
# ? May 3, 2019 23:02 |
|
i was hoping i'd be able to pick it apart just by skimming, but i haven't been doing any android programming for months so i don't remember any tips and tricks when it comes to the process lifecycle. you can tell i'm really good at android programming because i didn't notice a pretty obvious "oh this must be related to stuff they stripped out of the post" bit of code
|
# ? May 3, 2019 23:23 |
|
I haven't used it, but the docs for MapView say this:quote:Users of this class must forward all the life cycle methods from the Activity or Fragment containing this view to the corresponding ones in this class. In particular, you must forward on the following methods: so you might need to call through on all those events to let the MapView know when to tear itself down. If it's not getting destroyed, you'll have them hanging around - and you're passing them a reference to your fragment too, so it'll be keeping that in memory as well. Every time your activity is recreated (like by rotating it) you're creating a new fragment (calling its constructor in the fragment transaction) so you'll end up with those all piling up and anything those fragments have a reference to as well
|
# ? May 3, 2019 23:23 |
Yeah you're passing code:
|
|
# ? May 3, 2019 23:30 |
|
baka kaba posted:I haven't used it, but the docs for MapView say this: This put me on the right track, thanks! I’d built out this app from the Map example in Android Studio, but along the way swapped out a SupportMapFragment (which handles all this for you) for this MapView without realising the extra obligations that brought. I’ve swapped it back as I realised there was no need to handle it myself, and the leak has gone. Thanks again!
|
# ? May 4, 2019 08:19 |
|
No probs! I know you said you're new, so this might be a bit advanced, but probably the best way to troubleshoot this kind of thing is to do a heap dump (probably best to hit the garbage collection button first) It'll show you all the objects allocated in memory, you can sort it to see where all your memory is going, and if certain stuff is taking more than you'd expect. Probably the easiest thing to do is do the Sort By Package bit, find your app's package in the list (so you can just look at your own stuff), then sort by Allocation count and basically look at how many of your own objects are hanging around, and check if that looks right. Like you'd probably have seen several instances of your MapFragment, when you'd only expect there to be one, right? That's a big clue, and you can click on the different instances to see what's holding a reference to them (what's keeping them alive in memory, basically) and you'd have probably seen MapViews, which also shouldn't still be around. And then you go hmm, what is the deal with these MapViews... it's a good tool to learn at some point anyways
|
# ? May 4, 2019 20:29 |
|
baka kaba posted:it's a good tool to learn at some point anyways 100%. This tool will save you so much time. And once you get to the bottom of the leak it's usually always something that'll make you feel really stupid, like a listener causing a referential loop, or something like that.
|
# ? May 4, 2019 22:32 |
|
https://twitter.com/chrisbanes/status/1126899316818186241 "How do you open the navigation drawer then?" "Very carefully"
|
# ? May 10, 2019 20:21 |
|
Why do I get the feeling viewpagers are cancelled
|
# ? May 10, 2019 20:39 |
|
Feels like these gestures just get in the way of the functionality of half of all apps. Why does Google have to destroy all of the good parts of Android
|
# ? May 11, 2019 00:08 |
|
Ian Lake's in the replies on that tweet saying the gestures break part of the I/O showcase app :androidsmileythatsimnotlookingfor:
baka kaba fucked around with this message at 00:16 on May 11, 2019 |
# ? May 11, 2019 00:13 |
|
Been working on a bug at work where a ContentProvider is dying or not being started up or something. The app is split into multiple processes so it's probably some awful concurrency bullshit. I think we also have parts of the code that just get the database itself and then interact with it which might be a nono. Anyone got some dos+don'ts for working with these that arent in the official ContentProvider guide?
|
# ? May 21, 2019 01:39 |
|
brand engager posted:The app is split into multiple processes Dare I ask why?
|
# ? May 21, 2019 01:44 |
|
I don't know why, it was before I worked there
|
# ? May 21, 2019 01:48 |
|
brand engager posted:Been working on a bug at work where a ContentProvider is dying or not being started up or something. The app is split into multiple processes so it's probably some awful concurrency bullshit. I think we also have parts of the code that just get the database itself and then interact with it which might be a nono. Anyone got some dos+don'ts for working with these that arent in the official ContentProvider guide? What do you mean by "multiple processes"? A lot of commonly-used stuff in the standard Android API uses multithreading. The UI of your app (if it has one) is on a separate thread, AsyncTask calls use a background thread, etc. Is that what you're talking about?
|
# ? May 21, 2019 02:05 |
|
It runs in three processes. We've got one that has all the activities, one that has network stuff and native c/c++ junk, and a "utility" process that I cant remember what it's responsible for.
|
# ? May 21, 2019 02:25 |
|
So I'm making a little android app. It's my first project developing for a phone, and may I say: Good lord, android studio is godawful. It's full of tiny icons with no explanations, labyrinthine submenus, wow. Whatever. I've made my app with the desired functionality using React-Native. Great. It runs fine in the emulator. So, I want to get it on my phone. That's not playing nice with the debugging over USB, but that may be my phone being a cheap piece of poo poo factory second. So I found a guide to exporting a .apk on stackoverflow: https://stackoverflow.com/questions/16622843/how-do-i-export-a-project-in-the-android-studio/16622975#16622975 That goes great. Everything is like the pictures, until the build fails with an internal error: Error:Internal error: code:
This is irritating because this is a fresh install of all the latest stuff recommended by the react-native team at facebook- https://facebook.github.io/react-native/docs/getting-started Python2, the Android SDK, Android Studio, and the Java development kit. It would be wonderful if a fresh install of the recommended tools didn't fail by default. This looks like a dependency is missing. It's not one I'm intentionally using... But ok. Googling this gets me jack-poo poo for useful information. https://github.com/spotbugs/spotbugs/issues/931 https://stackoverflow.com/questions/55844077/findbugs-idea-classnotfoundexception-com-google-wireless-android-sdk-stats-int From what I understand, there was an old utility build into android studio called "findbugs." Findbugs is deprecated, and also causes this error to pop up? The new version is called "spotbugs". I am not aware that I am using either of these, but again, I haven't touched any settings in android studio. People say you can look at your plugins in Android Studio through File -> Settings -> Plugins. I have done that. It doesn't say I'm using either spotbugs or findbugs or even that either is installed. Even more baffling, this is the checked answer on Stackoverflow: quote:I think this may be the answer. I find that I cannot divine any useful information from that one. I gather that I may need to edit a gradle build file somewhere, but although I have spotted one or two candidates in my react-native project I am still in the dark as to A: which gradle file is the one to edit B: Really, what gradle is- I get that it's google's build tool, but not much more than that. If anyone has any insight into how I can get my app build/turn off/ignore this error, that would be wonderful.
|
# ? May 21, 2019 03:37 |
|
I can't directly help you with your problem, but I can tell you that you're inviting pain by using React Native. It's a poorly made multiplatorm solution that doesn't integrate well at all with the tools. Pretty much universally it turns out that people who use React Native end up taking more time to develop their app than if they had just made separate native apps. I realize if you're doing this for work then it's probably out of your hands, but I recommend doing whatever you can to change that decision. That is probably also your gripe with Android Studio. Things like RN aren't made to work with it and just add a big layer of pain. It's based on Intellij which is the best full IDE out there (distinct from heavy featured editors like VSCode), bar none. Compared to Xcode, which is the closest analog you can get, the comparison is laughable. Of all the things to complain about with Android development, and there are a lot, the IDE isn't one of them. It's really good.
|
# ? May 21, 2019 06:18 |
|
Interesting! Yeah, I was getting the sense from poking around that React Native was kinda dead/undersupported. I just built this one for fun and to learn some mobile work because I'm planning on doing some mobile stuff for work at some point. I stand by my initial complaints about Android Studio- for a first time user, unlabeled 15x15 pixel icons are pretty hostile. I'm sure it's fine once you're used to it, but it's a kick in the teeth compared to visual studio code.
|
# ? May 21, 2019 06:23 |
|
Vim Fuego posted:Interesting! Yeah, I was getting the sense from poking around that React Native was kinda dead/undersupported. I just built this one for fun and to learn some mobile work because I'm planning on doing some mobile stuff for work at some point. if you hover over the icons itll tell you what they do, and if that doesnt explain it then you can google the functionality to learn how to use it. also dont use flutter either.
|
# ? May 21, 2019 06:58 |
|
Vim Fuego posted:Interesting! Yeah, I was getting the sense from poking around that React Native was kinda dead/undersupported. I just built this one for fun and to learn some mobile work because I'm planning on doing some mobile stuff for work at some point. Definitely understandable, but as a professional tool its primary design motivation is not intuitive adoption by newcomers, but efficient use by experienced users. The same will be true of any professional tool that people are meant to work in for 8+ hours a day. I come from a background of of 3D work, and let me tell you, those tools are an absolute nightmare as a newcomer. But after a few weeks (or months, or years) you come to understand the decisions that were made to make the tools the way they are, and appreciate them. But there will definitely be some pain. Read tutorials, guides, watch videos, learn hotkeys, and you'll start to get comfortable. Regarding gradle, it's a broad build tool, not exclusively used by Android but that's certainly it's biggest area. I can tell you personally it was a gigantic pain in my rear end when I first started (I was not a very experienced developer when I started doing Android dev), but over time I've not only come to be comfortable with it, but vastly prefer it over other build tools I've had to use. NPM, cocoapods, CMAKE, etc all have their strengths, but they also all have very big downsides. Gradle has downsides too for sure, but IMO, they are far more manageable than the downsides of other build tools. Its integration with Android Studio also makes it much more pleasant to use. With time, of course.
|
# ? May 21, 2019 08:20 |
|
Yeah Android Studio has a lot of stuff going on in it, it's very dense so you kinda need everything to be compact otherwise it would be unusable without multiple monitors. There's definitely a learning curve, so don't expect to know what everything is (and you won't always need to know either) biggest tip - Ctrl+Shift+A and start typing (it's like F1 in VS Code only more powerful), or tap Shift twice for navigating to stuff also if you're having build issues, it's always worth doing Build > Clean and trying again, usually this is an issue if you jump around in source control and there are significant changes to dependencies or generated code. Could always try File > Invalidate Caches and Restart as a hail mary. Probably won't help in this case, there's a ticket about this kind of thing - the people affected seem to be saying it appeared in 3.4, so maybe try an earlier version like 3.3? Honestly though it's probably worth trying to get USB Debugging working on your phone if you want to develop on it Also I dunno if it matters, but you mentioned installing the JDK, but the AS team recommend using the OpenJDK that comes with Android Studio, so it might be worth a try
|
# ? May 21, 2019 17:14 |
|
Thanks! I'll see how it goes. From poking around it seems like Java, Kotlin, or C# are the way to go. Any clear leaders there or is it personal preference/company requirements?
|
# ? May 21, 2019 17:19 |
Write kotlin if it's a new app imo
|
|
# ? May 21, 2019 17:24 |
|
Just fyi, something they posted last week on Android Developers Blog:quote:Android development will become increasingly Kotlin-first
|
# ? May 21, 2019 17:26 |
|
brand engager posted:I don't know why, it was before I worked there The codebase at my previous job had two processes; the ui process and player process. The idea was that if the UI crashed for a dumb reason playback would continue in the background. This wasn't a great reason but was somewhat understandable. There's almost no reason to have multiple processes. You should ask about this. The database is going to assume single process, and the SQLite classes may help enforce concurrency issues. If multiple processes are using the DB, you're in for a bad time.
|
# ? May 21, 2019 17:50 |
|
PokeJoe posted:Write kotlin if it's a new app imo we're slowly converting everything to Kotlin because we suspect Oracle is going to start charging Google for licensing or w/e i wonder when Kotlin Native will be a [bigger] thing
|
# ? May 21, 2019 17:57 |
same and the kotlin classes are shorter and easier to debug
|
|
# ? May 21, 2019 18:11 |
|
Kotlin owns, definitely write it. But you'll still need to know Java cause a ton of libraries and AOSP are Java.
|
# ? May 21, 2019 18:21 |
|
On the other hand, let's look at what help can we get when we're stuck: https://stackoverflow.com/questions/tagged/kotlin - 23,106 questions https://stackoverflow.com/questions/tagged/java - 1,550,652 questions
|
# ? May 21, 2019 18:30 |
|
Now you have 1,550,652 problems!!
|
# ? May 21, 2019 18:50 |
|
Volguus posted:On the other hand, let's look at what help can we get when we're stuck: 90% of java questions on stack overflow are because some cute newbie didnt initialise their variable
|
# ? May 21, 2019 19:02 |
|
FAT32 SHAMER posted:90% of java questions on stack overflow are because some cute newbie didnt initialise their variable That could be true (quality/quantity bla bla) . so lets take a look at Kotlin. First question: "Kotlin: How to iterate through a collection from a specific position with indexes (skip N elements with indexes) ". Yeah. Q.e.d. On the other hand, if one is learning the language, what are the odds they will have some "cute newbie didnt initialise their variable" problem too. For which the answer will be at a google search away. Volguus fucked around with this message at 19:08 on May 21, 2019 |
# ? May 21, 2019 19:06 |
|
Volguus posted:That could be true (quality/quantity bla bla) . so lets take a look at Kotlin. First question: "Kotlin: How to iterate through a collection from a specific position with indexes (skip N elements with indexes) ". Yeah. What about it though? Seems like a pretty normal question, especially if you're just getting used to the functional paradigm instead of manually iterating over things
|
# ? May 21, 2019 19:36 |
|
|
# ? May 23, 2024 17:07 |
|
baka kaba posted:What about it though? Seems like a pretty normal question, especially if you're just getting used to the functional paradigm instead of manually iterating over things What does a loop have to do with "functional paradigm"? And "what about it?" It just looks a simple enough question, on par with the "initialized variable" questions java gets. Trying to come and say: but the kotlin questions are so much better, doesn't really fly. Remember, most are the same developers asking both.
|
# ? May 21, 2019 19:45 |