When should the ViewModels call Services and Isolatedstorage - mvvm

I'm using the MVVM-Light toolkit and storing my ViewModelLocator in App.Resources. I noticed that my ViewModelLocator class gets created before the Application_Launching event gets fired, and according to this Link from Microsoft you shouldn't make any Network calls or access Isolated Storage until after the Application_Loading event has fired and the application is loaded.
So my problem is that my ViewModelLocator creates my ViewModels in its constructor and the ViewModels in turn are making Service calls and accessing IsolatedStorage. So how are you suppose to do this properly? And how do I wait for the app to be "Loaded" when there is no Application_Loaded event?

My understanding is if the load calls are asynchronous, it meets your requirments.
Otherwise, you can always implement your own flag system/ delayed delegate calls after load event completes.

Related

Create a variable/object/resource that is accessible through entire application in ZF2

To be specific, I need to create an array variable that will be used for caching data, but I don't want to use ZF2 Cache Adapter.
I've tried to create a invokable class that would be used to instantiate object of my class that contains methods for setting and getting values from array that is also defined as a property of that class. As far as I understand, service manager treats all services as shared by default, which is supposed to create only one instance off my class when I get the service by service manager method get for the first time. But this doesn't work, if I get that service in different actions in my Controller class, which is what I need to do. So, how am I supposed to achieve this effect? Create an object that is available application-wide?
I had this kind of problem with managing a cart.
My cart is modeled by a CartManager, which is a unique instance for a user (session) and until paiement (cart is persisted in database).
I register my CartManager as a Service to build the first instance, this instance is built during an event handler attached on MvcEvent::EVENT_ROUTE, once built I override the CartManager service with my Instance, this way wherever I call the service, my first instance is served.
Then I persist (session or database) my Instance in an other event handler attached on MvcEvent::EVENT_FINISH.
All the event handlers are attached in Module::onBoostrap()

Determining when GWTP place gets loaded completely

I use GWT + GWTP in my application. I have some places with nested presenters. I would like to execute some code after loading of a place (after place reveal is complete with all of contents and server calls, alongwith all nested presenters). Scheduling deferred or finally command does not work and gets called before place load is complete.
Is there any way to detect the completion of revealing of place?
Since you'll be waiting for a number of server calls to complete, I suggest you send an event through the EventBus upon completion of your server calls. The root presenter in your presenter hierarchy will subscribe to those events. Once all required events have been received by the root presenter, you'll know that all server calls have ended.

When we use delegate and Call back in iOS?

I'm very new on iOS application development so please explain me about delegate and call back. When we use use call back and delegate?
Call backs are used to allow an API or service to provide information to your code when certain events occur (e.g. when a task has completed). This is useful in asynchronous programming, e.g. when you want your current thread to get on with something else, or to allow the user to continue using the UI. (i.e. a call back is a function or lambda you have written, which is passed as a parameter to another method)
A delegate is the 'signature' (the 'type definition' of a method, including parameters) that a method (such as a call back) must provide in order for it to be useable as callback or event handler.
Edit Just to be complete, Delegation is also a design pattern, whereby the responsibility of control or action is delegated from one object to another.
Big piece about delegates here on the dev centre:
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html
There is a tutorial app using callback/delegate
http://brandontreb.com/objective-c-programming-tutorial-creating-a-twitter-client-part-1/

Is there a sendToActivity() method?

I have a program with about 8 Activity classes, and 1 Application class. I want my Application class to be able to communicate with every Activity, but on its own terms. I don't want the activity to ask the Application for data, I want the Application to send the Activity data. The problem with this, is that depending on the current state of the program I'm unsure what Activity will be open.
Is there a method of some sort which will send information from the Application to the CURRENT activity?
The Application class connects with an embedded Bluetooth Device and needs to receive different pieces of data depending on which Activity the user is currently in. I originally had it as a regular class, which was initialized in the MainMenu of my program and passed a Handler. However, it seemed like weak design to pass that Handler from Activity to Activity time and time again.
You could use a Callback Method
Every Activity has it's own callback method and registers that method onResume() in the Application Class. (it's like an onApplicationWantsToDoSomethingWithMeListener() ;)
or why not a Service in background? instead of the Application, since what you want sounds like a Service. More details?
EDIT:
I made a similar application with bluetooth, you should definetly use a Service for that, but you can communicate with your service per Application. Say the Service calls the callback in the Application look here for an implementation uf such a thing

How create a custom event handler for ctcall center? iphone

I am working on an application in which i have a requirement of detect call log info.
Means when ever a call coming and going and then after attending call that will disconnect. So i have detect and send a notification when call disconnect.
For this requirement i have done so much r&d and get some results but when i go through Apple's doc for core telephony framework then there is class "CTCallCenter". This class provide a event handler which will invoke app whenever a call state change.
Now problem is that when i go through document of that class then i get som texts which is shown below
To handle such call events, define a handler block in your application and assign it to this property. You must implement the handler block to support being invoked from any context.
link of apple doc for core telephony framework
In above text write down that u have to create a event handler and assign to property then it will handle call events.
So problem is that how I create a custom event handler and how make a property and assign to my custom event handler?
Thanks in advance...
Take a look at CoreTelephonyDemo. You will find your answer in there.
The event handler is a block. You can also look at Blocks Programming Topics