How do I navigate through and understand the documentation in Android? - android

I got one piece of code to study and I was puzzled for a long time because I tried to make my own version of it and it broke then I tried commenting the original code step by step to see when it failed and it gave me a null pointer in a getView method after I commented the declaration of one variable it used. I wasn't seeing this method being called anywhere and searched a lot for an answer until I found this:
When is the getView() method of ListView called?
It esentially says that getView getts called whenever an item is passed to the adapter through the setAdapter method.
I look all over the View docs, Adapter docs, Inflater, etc and couldn't find any piece of information to tell me that this happened, not even the setAdapter method itself says anything about this behavior. Is this just a documentation error or is there some general guideline I'm not following correctly?

I think you are going in the Right direction, if you are breaking into the code and hitting road blocks. The best resource to Study API's for Android is android developer site itself
http://developer.android.com/reference/android/widget/Adapter.html
PLus the [android] tagged questions on StackOverflow.

Related

'this#ActivityName' is not captured error Android/Kotlin

I'm repairing my friend's code and got confused.
My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error:
To be honest I'm not sure how to fix it. He is coding in Kotlin (Android 10).
Activity that contains EditText:
And XML:
This is how it looks when debugging:
The app started working just fine after running "File -> invalidate Cashes/Restart" option, I just don't understand where this warning came from and how to fix it because the error remained unchanged (even though the app works). Do you have an idea how to solve it?
All the best!
fyi lambda expression like setOnClickListener from kotlin is not debuggable, see here.
if you want to debug variables inside setOnClickListener you should use the normal one e.g. setOnClickListener(object: View.OnClickListener {..})
sometimes there will be problem in auto generated binding files, if so it will be solved after invalidate cache and restart ide. sometimes the warning/error show but the project and complied without errors. so no need to worry about that. for next time post the code as code not screen shots.
I understand that the question is regarding evaluating expression, but there is a way you can read variables from your debugger console, even if you're inside an anonymous callback. I found it helpful sometimes. Here are the steps:
First enter debugger mode inside of your anonymous callback,
In your debugger console, look at the right side for "Frames"
Within Frames under , you'll see stack of function execution first top one on the list is the latest:
Click on row(s) below the latest function, until you find an instance of your activity AddInformationActivity. You will see the activity instance on the right side window under Variables. Don't go as far as selecting functions browned out, because those are from internal libraries.
When you see you AddInformationActivity instance, you can expand it and see its variables.
Hope that helps!
It's not a beautiful way, but if you create a method like this:
private fun debug() {
println()
}
and add a breakpoint on the println() it'll capture the activity.
(Don't use TODO as it'll crash the app with a NotImplementedError once called.)
I have this method now in my code all the time to call it whenever I need it.
I know, that question is old, but I just stumbled over it and needed a way.

Is there a way to trace who invoked onNext() on a Subject, in RxJava(2)?

I am developing an Android app (It doesn't matter though) using RxJava2, and in some singleton there are some PublishProcessors.
And there are a lot of .onNext() calls on these PublishProcessors all over the project.
Now in order to debug, I need to know, on every .onNext() called, which line in my project invoked this .onNext().
Is there a way in RxJava(2) that I can achieve this?
I think you can use Frames tab in Debug menu.
For example, in this case, MainActivity line 18 trigger onNext
Ah, thanks to #PhanVanLinh, I found a solution that worked for me.
(Actually it has pretty much nothing to do with RxJava...)
You just need to print the stacktrace using Thread.currentThread.stackTrace and print it to your own string inside doOnNext(), but remember to do it before .observeOn() so that the thread won't switch, it must stay at the original thread that called .onNext(), otherwise you won't get meaningful information.
Then you will know which line that called .onNext().

what should callerContext param be for Fresco's prefetchToBitmapCache?

In order to implement image pre-fetching, we get the ImagePipeline and call prefetchToBitmapCache on it. however, both the API Javadoc (http://frescolib.org/javadoc/reference/com/facebook/imagepipeline/core/ImagePipeline.html#prefetchToBitmapCache(com.facebook.imagepipeline.request.ImageRequest, java.lang.Object) and the plain doc (http://frescolib.org/docs/using-image-pipeline.html#) are incorrect. specifically , they leave out the description and example for what the second method parameter is. I am talking about the Object callerContext . which since its an object isn't an android Context. I'm guessing that because the type is an object, not a Context. Could the documentation be updated and/or someone explain what the caller context is supposed to be?
Thank you!
So I posted this question a while back on the fresco github (https://github.com/facebook/fresco/issues/609) and I was told the documentation would be updated. I'm posting my results here since it is likely others might look here. I still haven't seen any updates to frescolib.org or anywhere else. I decided to figure it out myself. Basically, if you're using SimpleDraweeView and its respective ImageRequest (which the prefetch call needs) , then you would notice that setting the uri on the view creates a DraweeController with a null callerContext. I figured that might be what is needed here. Sure enough, I made the call to prefetchToBitmapCache(draweeController, null) and its prefetched! I know that because I waited for a bit and turned off the data. also this call was only active on a select imageview. the other did not load. I can't be sure this is the right way to do it, ntil they come out with the right documentation. but like i said it works.

Android Minesweeper project(from codeproject.com)

Here is the link of the Minesweeper project on codeproject.com.
I just wanted to ask one thing here. I completely understood the logic and algorithm this guy used, but when he called the showMineField() method inside startNewGame() method , he called it after createMineField(). I am really confused! Shouldn't the layout be set before setting up mines and handling the user click events? But the code seems to work fine. If I just call showMineField() inside startNewGame() , it gives me NullPointerException.
This is because you cannot show a mine field before creating all the objects.
It is like trying to run without legs. If you call showMineField() that is using objects that have not been initialized. Thats why you are recieving a NUllPointerException. Nullpointer is throws when a method is trying to be call on an object that has not been created yet. createminefield() initialzes everything so that nullpointer is not thrown

WindowManager.LayoutParams why is there a setTitle method?

So yesterday i was programming and suddenly i came across the setTitle method in the WindowManager.LayoutParams class, why would this class like this have a setTitle method? Where is is used for? The documentation does not say anything about the function.
My guess is that it could be used for debugging or something a like, but other than that i don't have a clue.
And why would it be declared as final method? Because it's not ready yet for us to override it?
Just wondering...
Note: Both answers below are some how "correct" and offer good information, but can only accept one.
getTitle
setTitle
Going through the source code for WindowManager, it seems that the title isn't actually used anywhere, except in the debug and parcel writing methods.
Furthermore, searching google for +"windowmanager.layoutparams" +".setTitle()" site:grepcode.com doesn't seem to return any results where the setTitle() and getTitle() methods of WindowManager.LayoutParams are actually used in production code.
I'd say that the Android engineers felt that maybe at some point of time in the future they might need a title property, and put it in as a stub.
Well There doen't seem to be any usage for this layout parameter value anywhere.
It seems like a place holder for now.
I only managed to find these tow cases where it has been used:
SoftInputWindow
and
StatusBar Service
And visually both has no effect (at least on my device and emulator)

Categories

Resources