I'm developing an Android app for Chromecast which makes use of the Chromecast Companion Library (CCL) together with a MediaRouterButton. When the first activity is created, onCastDeviceDetected is called and MediaRouterButton is set to visible. The second activity is created from within the first activity, but no onCastDeviceDetected is called in the second activity!
What is best practice for keeping state of discovered Chromecast devices with the combination of multiple activities, MediaRouterButton and CCL?
In CCL version 1.8 onCastDeviceDetected was always called when starting a new activity, so this issue seems to be introduced (with purpose) in version 1.9 ?
I am not sure if what you are asking was ever working differently; I looked at the code and there hasn't been any changes in the behavior around that but I could be wrong.
Right now CCL doesn't provide an API for you to do that. From CCL's point of view, availability of routes hasn't changed when you move from one activity to another so it doesn't fire that callback (and the intention was not to do that either). The problem you are facing can be addressed by either of these:
Keep track of the route availability in, say, your Application instance; register a VideoCastConsumer in your Application class and listen to onCastAvailabilityChanged(). Keep the result in your Application instance and then when you start a new activity, ask your application instance if there is any cast device or not (based on the preserved value that I talked about); that would give the initial state. Have your activity register a consumer with the same callback so from that point on, the activity is self-contained as long as it is alive.
File a feature request for CCL so I add an API to get you around the need to add that piece in your own application instance.
Related
I am tracking custom events in Application Insights. In this problematic case I issue one call to "trackEvent" in my browser-front-end when the user loads a component (I am developing an Angular application).
In my Application Insights I run a query to list my custom events. Now in the results-list I have the same events with all fields identical (even the timestamp with miliseconds). Only the itemId is different.
Where could those multiple events of just one call to trackEvent have originated?
I do not have any relevant source code to offer, since I am only using this one call of trackEvent in the library applicationinsights-js (https://github.com/Microsoft/ApplicationInsights-JS)
Well here it goes:
AppInsights.trackEvent(myName, myProperties, myMeasurements);
In my case I could solve the problem by setting
config.isStorageUseDisabled = true;
in the configuration-object that is passed to the downloadAndSetup-Method of Application-Insights-JS. I also set the maxBatchInterval to 0, so that I would not lose any Tracking-Events. I am not sure about that though.
Here is a common scenario: app is installed the first time and needs some initial data. You could bundle it in the app and have it load from a plist or something, or a CSV file. Or you could go get it from a remote store.
I want to get it from CloudKit. Yes, I know that CloudKit is not to be treated as a remote database but rather a hub. I am fine with that. Frankly I think this use case is one of the only holes in that strategy.
Imagine I have an object graph I need to get that has one class at the base and then 3 or 4 related classes. I want the new user to install the app and then get the latest version of this class. If I use CloudKit, I have to load each entity with a separate fetch and assemble the whole. It's ugly and not generic. Once I do that, I will go into change tracking mode. Listening for updates and syncing my local copy.
In some ways this is similar to the challenge that you have using Services on Android: suppose I have a service for the weather forecast. When I subscribe to it, I will not get the weather until tomorrow when it creates its next new forecast. To handle the deficiency of this, the Android Services SDK allows me to make 'sticky' services where I can get the last message that service produced upon subscribing.
I am thinking of doing something similar in a generic way: making it possible to hold a snapshot of some object graph, probably in JSON, with a version token, and then for initial loads, just being able to fetch those and turn them into CoreData object graphs locally.
Question is does this strategy make sense or should I hold my nose and write pyramid of doom code with nested queries? (Don't suggest using CoreData syncing as that has been deprecated.)
Your question is a bit old, so you probably already moved on from this, but I figured I'd suggest an option.
You could create a record type called Data in the Public database in your CloudKit container. Within Data, you could have a field named structure that is a String (or a CKAsset if you wanted to attach a JSON file).
Then on every app load, you query the public database and pull down the structure string that has your classes definitions and use it how you like. Since it's in the public database, all your users would have access to it. Good luck!
I am confused of how an iphone app goes when it start running. I mean when I am trying to write a app, I get confused and lost of terms like "viewDidLoad", "viewDidUnload", "dealloc", "applicationDidLoad" etc. I have no idea when one comes first, which one comes later when an app runs. For instance, say, I would like to add a view(or picture) showing my app logo when the app is just opened (just like what most apps would do). So, where (viewDidLoad or applicationDidLoad) should I put my code in?
Well, this is just an example. I will appreciate it if you can tell me the answer. But what I am most concerned is about the life cycle of running a app, i.e at which state, which method will be called. Thanks in advance!
To start, you might want to know this:
the first code you get to run after the application has finished launching, is the one you put in the Application Delegate in the method application:didFinishLaunchingWithOptions. The app delegate is the class that is set to receive general notifications about what's going on with the app, like it finished launching :)
The other kind of 'notifications' of changes in the state of the app, or the life cycle of views are:
-viewDidLoad
-viewWillAppear:animated:
-viewDidAppear:animated:
-viewWillDisappear:animated:
-viewDidDisappear:animated:
-viewDidUnload
Those methods are declared in UIViewController, and you can implement them in your UIViewController subclasses to customize the behaviour of a view in those situations (each method name is self explanatory)
The life cycle of an app is pretty well covered here: http://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/iphoneappprogrammingguide.pdf page 27
About showing a logo when the app launches, apps achieve that setting a "splash" image by putting its name in the info.plist property-list file, in the UILaunchImageFile key.
I think the official developer guide delivered by apple will help you. This is the link:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html
HI i am new to the the whole programming thing, i have been given a task to multithread 4 stored procedures where each thread runs asynchronously so that the user can get output real quick i have to do it using WCF can anyone help me out with this. Initially what i am trying to do is taking each procedure and getting how much time it takes to execute using parametrizedthreadstart, but i am not sure how to go about it.
Considering you are new to the whole programming thing, you can follow these very basic steps to get thing done.
Create a new WCF service.
Add 4 methods each calling one stored procedure.
Add parameters to the methods which are required by stored procedures.
For Example if your stored procedure is - MySP(varchar name) then your WCF method will
be - MySP(string name);
Now depoly your service in IIS or windows service or Console App or wherever you want.
Create a client application, again it could be anything ConsoleApp or Win Form etc.
Add a reference to your service.
Instantiate service class and call there Async version. By Async I mean there you'll
see all of the four methods with Async attached.
For Example you will find your MySP(string name) method as MySPAsync(string name)
Also there will be MySPCompleted event, subscribe to it.
Now all of your methods are running asynchronously whenever they finish execution they'll call your subscribed methods.
I hope this helps you get started :)
There are a couple of different ways to do this. At the highest level, you can place each service request in it's own service endpoint. This could be defining endpoints for each method, or if you are hosting in IIS, placing each service it's own website. At the lower level, you could define callbacks for each method so that WCF will not block while the method calls are taking place.
Is it possible to have a bi-directional web part connection? I am aware that a web part can be both a provider and a consumer but it seems only one connection is allowed between two web parts.
What I am trying to accomplish is a bi-directional connection where a field in web part A can update web Part B and a field in B can update web part A.
You can do this in several ways.
The main things to understand are:
You're in complete control of the interface the web parts share
By default only the consumer knows anything about the other web part
Here is then a couple of ways to implement what you describe:
Option 1: Pull/Push:
You can make your interface such that the consumer can pull the information it needs by either calling function or getting property values
And the consumer also pushes the information the other webpart might need by calling functions or setting property values.
Option 2: Consumer announcing
Here you define your interface (and way of using it) such that when a consumer get's a connection it make a call back through the interface to give the producer a reference to the consumer. This reference can then implement the same or another interface any way out want.
Now both the consumer and the producer has a reference to another web part where they can get the information they need.