I can't seem to find the answer to this question I'm having:
Is the method from the ACRA library ...
ACRA.getErrorReporter().putCustomData(Name, Content);
... thread safe?
I'd like to call it from two different threads and I'm not sure if i should or not.
I've searched through the documentation but I wasn't able to find anything related to this unfortunately, or maybe I'm just a bad Googleler :)
If you're not sure, buy some insurance:
ErrorReporter er = ACRA.getErrorReporter();
synchronized( er ) {
er.putCustomData( ..., .... );
}
So I think I've figure it out.
Looking through the code I've noticed that the putCustomData method is in fact a call to a HashMap's method, more precisely put.
Upon further search I've found that the method put is not synchronized.
So the answer is no, calling putCustomData from two different threads can create problems for you.
For a solution to the problem: see 323go's idea below. In my case, I already had a singleton class which I used, so I just placed a synchronized method in that class in which I called the putCustomData method.
Note: If I am wrong, someone please let me know, but this is what I was able to find out.
Related
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().
I am new to programming. Can you please explain what the difference between notifyDataSetChanged() and Adapter.this.notifyDataSetChanged() is? I think it has something to do with that context stuff?
I´m wondering which one I should use for my RecyclerView changes.
They are likely one and the same. this is a Java keyword to specify the current object, and the only reason you would have to specify Adapter.this before the method is if you were in an inner class where this would refer to something else.
could someone please explain me the meaning of this `ofRegisterEvent' method:
#ifdef TARGET_ANDROID
gpsStatus = 1;
gpsCtrl.startGPS();
ofRegisterGPSEvent(this);
#endif
I'm not completely able to figure out why I have to use that.
Thanks
I'd research event handlers if I were you. It will also likely utilise this class:
http://openframeworks.cc/documentation/events/ofEvent.html
It's hard to say without seeing more but it appears to be adding a passing in details about the current class into what could be a listener.
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.
I need help with using an if statement in java, here is my code :
if(ans==1)
{
txtans.setText("This is a Prime Number");
}
else
{
txtans.setText("This is NOT a Prime Number");
}
if I remove the setText methods in both statements my program works, but when I leave them there and the program finds ans, then it quits, I'm wondering whats wrong with the statements? or is it not possible to use the setText method within if statements..if so how do I overcome this? What I want to do is print a string to the TextView layout when the ans = 1, any suggestions?
Yes, you can run txtans.setText() in an if statement just as well as you could run it if it wasn't in an if statement. You likely just don't have txtans initialised properly.
A quick google search brought up this as a way to print text to a textview.
Check your code, this erros usually comes when use findViewById() method in a wrong view.
In the activity you use like this findViewById(), maybe you need to call yourView.findViewById();
(If you post your class we can help you with more detailed answear.)
Also note that it is not allowed to call methods from Views from another Thread which created them. But a LogCat output including the Error will enlight us for shure :)
txtans might be NULL and you are trying to access a member of a NULL object.