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.
Related
In this Q&A, it says there's no difference. And some people says annotation is better or using constructor(mockk<*>()) is better.
For me, if they are equivalent, less line of code(not using annotation) is better.
Many sample code shows #MockK is used for the values that pass to Class such as ViewModel/Activity or Fragment. On the other hand, mockk<*>() is used for the classes that have its behaviour or data class, etc
There must be some differences since one is annotation and the other is using constructor. And there must be some reasons why each of them are created, not only one of them.
If you know this, could you please answer it?
Is that possible to do getActivity().findViewById() using #Bind. I want to bind view in another fragment using this way. But so far it can only be done in standard way :
Button mSubmit = (Button) getActivity().findViewById(R.id.btnSubmit)
I'm not sure I fully understand the question, but it seems like using the two argument form of ButterKnife.bind would work -- pass getActivity() as the 2nd argument.
(I suspect this may have already been answered -- if someone wants to find an existing answer, please do.)
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.
There is a lot of information out there concerning Parcelable in Android. After looking around, I couldn't find a nice solution for my problem.
So, I need to create a class (let's call it "MyClass") which extends a custom class someone else wrote ("HisClass"). There are many instance variables in HisClass, some of which are objects of custom classes, themselves. I want to pass a MyClass object from one activity to another and I realize, I need to make it Parcelable. But what about the instance variables which are custom objects?
Reading this, I think I need to make every single custom object implement Parcelable. Since, there are many custom objects in MyClass and HisClass which again have custom objects for instance variables, doing that seems like a bad solution to me.
Is there a better way? Maybe, I am just being totally blind here. Hope someone can help me.
Well, you can make use of Serializer, but it would result in a slow performance. AFAIK, implementing Parcelable is the best way to passing data. Additionally, don't try to complicate yourself by creating so much complex data structure to pass using Intent.
Either use Parcelable for something cheap/light-weight/less-in-amount or something else like output to files...and passing its paths.
I'm looking for a way to bind a visual component, lets say a TextView and some value.
I have a background service that changes the value and I want that change to be reflected on a TextView in an automatic "Flex binding" way.
There is any Android built in tool to do that?
I have not tried it myself, but take a look at this: http://download.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html
And this: http://download.oracle.com/javase/tutorial/javabeans/properties/bound.html
And this: http://developer.android.com/reference/java/beans/package-summary.html
It looks as though you can implement your 'value' as a bound property, and then register an onPropertyChangedListener, wherein you would then update your TextView.
Am not sure if I understood your problem correctly, but here is one way to get auto-binding kinda stuff.
Create a Model class and a static variable on that. Use your TextView.text to populate using this ModelClass.staticTextProperty. Now, whenever you update this ModelClass.staticTextProperty using any background service, it will be updated in the view.
Hope it helped.
I do not know how Flex does it exactly, but greenInject may offer something similar:
https://github.com/greenrobot/greenInject/wiki/Value