what should callerContext param be for Fresco's prefetchToBitmapCache? - android

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.

Related

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().

Is there anyway to pass Image data through an intent?

I know how to do this converting it to a bitmap, but I want an Image (android.media) on the receiver side.
Thanks in advance.
If you want to pass only one bitmap at a time, I suggest creating a static variable in a class. and assign the bitmap object to it, and use it in the receiver class.
But if this is very big bitmap, it may cause OutOfMemory issue.
You probably don't want to do this. Even if you create a Serializable or Parcelable object that includes your data like this:
http://www.javacodegeeks.com/2014/01/android-tutorial-two-methods-of-passing-object-by-intent-serializableparcelable.html
which you may be able to do, by creatively encoding your image.
But an Intent has a limitation in size. See this post here:
Maximum length of Intent putExtra method? (Force close)
It says 1MB, but in my experience it might be as high as 4MB, depending on the platform (I may have that wrong, I don't have a specific reference to Android documentation to support it, but I see errors that appear to support it).
I'm sure you can move a lot of images within this restriction, but for any that fall outside of it, you will need a "work around" - which you should then probably make the "standard" and avoid the issue altogether.

How do I navigate through and understand the documentation in 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.

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)

In monodroid enviroment how do I get the Context outside of the View

I want to load an asset and the only way I can see to do that is with
Context.Assets.Open();
I don't see a way to get access to Context without passing it around. I really don't want to pass it around
To answer my own question:
Application.Context.Assests.Open()
is what I was looking for. For some reason I just couldn't see it.

Categories

Resources