What is the difference between Android Fragment instance variables and the bundle arguments?
When to use what?
A Bundle is sort of presistent data. The Android runtime may restart you Activity or Fragment for example on orientation changes of your device. The variables of your first instance (let's say the one used in portrait layout) are not present when Android creates a second instance that it will use for the landscape layout.
By placing state/variables in the Bundle the new instance of your class gets back the variables, when it's recreated.
You can add the instance variables you want to keep to the Bundle in the onSaveInstanceState() method of the first instance. When the second instance is created, you get these in the Bundle that is passed to your onCreate() method.
Related
Hi I am new to WatchKit development. I want to know that can I update a single interface controller with multiple data for button clicks
You could have many different objects in your InterfaceController, such as labels, image views, etc.
Updating WKInterfaceLabels
You should call the setText() method on the corresponding label.
For example, you have a button and a label, and you want to print "Hello" on the label when the button is clicked. In this case, you should connect an action to the button in your interface (by control-dragging button to the code), and then add the following code in the method created:
Swift
label1.setText("Hello")
Objective-C
[label1 setText:#"Hello"];
Updating WKInterfaceImages
You should call setImage() or setImageNamed() methods on the corresponding image view.
First, the image should be located in the Asset Catalog of your WatchKit App Target, must be bundled or available as an UIImage. Then you could use these codes:
Case #1: Available as file in bundle or Asset Catalog
Swift
image1.setImageNamed("imageName")
Objective-C
[image1 setImageNamed:#"imageName"];
Case #2: Available as an UIImage
Swift
image1.setImage(image)
Objective-C
[image1 setImage:image];
If you want to have animated photos, try this link.
Conclusion
To update WKInterfaceLabels, you should call the setText() method on the corresponding label.
To update WKInterfaceImages, you should call setImage() or setImageNamed() methods on the corresponding image view.
Resources
WKInterfaceImage Class Reference
WKInterfaceLabel Class Reference
I have propel classes that implement the preSave method. This is a hook where some fields can be automatically updated at each saving operation. This is needed in order to save the date of last update and the user of the last update.
The problem is that the model classes have no access to the service container, where I can get the user id (to set into the last update user field). Model classes cannot (at my knownledge) be declared as service, as these are kind of entities, instancied by propel itself and not by the service container.
The only solution I see is to have a "real" singleton (with a static instance) holding the user object, that I would instanciate during the bootstrap of the application, then any model class could access it.
Any better idea?
For anyone having the same propel, the given bundle only adds the EventDispatchor behavior to Propel, which means that you can manage propel events in the same as Symfony does, but it is separated from the Symfony container (it seams it is using it own container).
But glorpen/propel-bundle is doing this job very well, you can really define service that listen to Propel events, using simple tags.
I am working in an android application and I want to pass a List of Objects from my fragment activity to Fragment. And I am using android support library to implement fragments since minSdkVersion is 8.
I have already passed these List of Objects from one activity to another activity by implementing my model classes with Parcelable.
So please suggest me a good solution to pass my List of objects from my fragment activity to Fragment. .
I have a class which I load via dependency injection within Symfony 2.
It has a number of default private variables which I can override with setters.
Problem is, once one of those default values are set to something else within a page, there is no way to set it back automatically.
I don't want to call the class again using new as it removes the usefulness of the dependency injection.
So, does Symfony2 support Object LifeStyle, or do I basically need to write a public function which resets all of the defaults back to normal and call it each time it is required.
As an example, I use a class to get remote files. It has defaults for UserAgent, Accepted Language/Encoding, Method etc. But if I set the Method to POST, instead of the default GET for one call in a page, the next time I call it, it is still POST, where as I wish it to be the default GET once more, which it would be if I used new instead of via dependency injection.
Add scope: prototype to your service definition. This will ensure you get a new instance from the container each time you request your class. And of course the instance will have the default values.
http://symfony.com/doc/current/cookbook/service_container/scopes.html
I've got a number of modules in a Prism application which load data that takes 3-8 seconds to get from a service.
I would like to be able to say in my bootstrapper something like this:
PSEUDO-CODE:
Customers allCustomers = Preloader(Models.GetAllCustomers);
And this would run in a background thread and when the user actually needs the variable "allCustomers" it would be fully loaded.
Is there an automatic service in Prism/Unity which does this type of preloading?
No, there is not.
However...
What you can consider is adding your ViewModel with a ContainerControlledLifetime to the container in your ConfigureContainer method that the views can use. You'd kickoff your threaded request in the constructor of your ViewModel and allow Views to pull this ViewModel out of the Container.
Even if they grab the ViewModel out of the container before the GetAllCustomers method is done firing, they will be notified correctly if the property you store the customers in implements INotifyPropertyChanged correctly.
If it was more appropriate, you could also do this from the Modules (in the Initialize method), rather than in the bootstrapper (for instance, if your Module was what actually knew about your Customer's Model).