set data binding null like view binding - java

One of our dear fellow android developer asked that Is it necessary to set ViewBinding to null in Fragment's onDestroy()? and the answer was yes. i don't use view binding per se, is use Data Binding mostly for fragment bescause of suggested single activity method. But i did not find any reference to set data binding null in onDestroy or onDestroyView. In data binding we can use setLifecycleOwner for our data binding. Life cycle owner can be this as the fragment itself or requireActivity. My two Questions are :
Question 1 : like view binding do we need to set dataBinding null ? (data binding kinda does view binding's job that's why i'm asking this Question)
Question 2 : if yes then what really setLifecycleOwner for ?

Related

When to use ViewModel or Fragment newInstance function?

So the question is simple: When is it best to use a ViewModel and getting data from that versus using the newInstance function on a fragment and passing the data through the creation.
I've tried googling it, but there doesn't seem to be much out there. Not anything I can easily seem to find.
ViewModel together with LiveData will store the values throughout the life cycle of the Fragment/Activity. It can also observe the underlying data so when the ViewModel changes your views will be automatically notified and updated. Read more about MVVM.

Can we send View object as parameter within OnCreate() method?

I'm a beginner Android developer. I'm still learning new things every day, and while learning I have heard this question quite frequently: What will happen if we send View object as parameter within OnCreate Method? I have searched about it but didn't find anything helpful. I just want to know is it really possible and if so then please explain the scenario.
oncreate() called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state.

Why (and how!?) is Android changing my references?

I have quite a bit of experience in Java, and up until I noticed this bizarre behaviour in my first android app I thought any references I create will always point to the same Object unless some code with access to the reference changes it.
I had an activity with to two fragments under it inside a ViewPager. In the activity I maintain references to the two fragments (private fields) to interact with them. On orientation change my fragments are stopped (and apparently destroyed as well) so I am creating them again from the activity because they have complex state that I don't wanna bother "parceling" or "serializing" into a bundle... This may not be best-practice, but hat's not my question though. It's more about how the Android JVM and libraries manage to automatically change the activity's private reference to the fragment (which I'm setting in the onCreate method) to point to an automatically constructed fragment using the default constructor. I understand that android can destroy fragments and construct new ones later and invoke onSavedInstanceState or whatever to allow the developer to recover their fragment's state; but how does it also find and change the existing reference in the activity to point to the newly constructed fragment.
This seems to be a JVM-level feature (more than just simple reflection), that allows Android to figure out all existing references to the fragment (or is it? what am I missing?) in order to modify them when a fragment is re-created. Whatever the case, is this and Android-specific JVM feature? Does a similar thing exist in other Java implementations such as Oracle Java or OpenJDK?
Please keep your answer about the weird automatic reference juggling part, and not about how I'm managing the activity/fragment life-cycles (I'm aware I could do better, and I'd love to read your suggestions, but keep those in the comments or the second part of your answer). I've done a lot of debugging and that's what I observed: the fragment reference was indeed changing, and I managed to fix it by manually resetting the reference to the reference I explicitly set in the onCreate method - a seemingly redundant operation.

Debug Java object attributes in Eclipse

From my UI, I pass some object attributes to the server.
So I pass an object say 'filter' as below;
{
attr1: 'val1',
attr2: 'val2',
attr3: ['val1','val2'],
}
My question is while I get this simplistic view of what gets passed on the client-side (using Firebug/Chrome Developer tools), I am looking at a similar thing in the Eclipse Debug View.
I have tried using Watch/Inspect in the Debug view, but it seems to be displaying a lot of additional info which I do not need.
So it displays HashMap as 'table', then says before, after, etc OR in short, I have to keep expanding lot of stuff just to see simple data !!
My question is how do I get to see just the attributes like attr1, attr2, attr3, etc
You can use Display view in eclipse. there you can write and evaluate any expression.
This you can enable from Windows-> Show View -> Other -> Search for Display.
Hope this help
You can use Expressions view of Eclipse while debugging. In Expressions view you can get the value of all your attributes directly e.g. mayMap.getValue("attr1")

JSF : Passing data between 2 views

I'm a french computer science student, and I have a small JSF project for school. I'm a little bit noob and I try to pass data between 2 view but I fail.
First I have a view which list all my customers, in a datatable. In this datatable I have a link to show a customer profile. I use, for both view, a CustomerController which is a requestscoped managedbean.
Before I use a global sessionscoped controller but I think it's not the good way to pass data.
Then I found this article : JSF Best Practices, it recommend to use to pass object between views. I didn't manage to make it work.
And finally I found also this question from Stackoverflow : f:setPropertyActionListener sets null value instead of intended value which use
My question is : what is the best ways to pass data ? And how manage it ?
It's explained in this article from BalusC. You need to send id of your selected item to second view through h:link and catch it then with <f:event>.

Categories