Can HoloLens enforce a single instance of my app? - unity3d

When opening an Unity app on the MSFT HoloLens it first creates a blank white box for the User to position and place via gestures. After the user has placed this white box, the application launches. The user can exit the app (but not necessarily close it) by performing the 'bloom' gesture. The app won't be running and the previously mentioned white box should re-appear (to denote this 'paused' state, as it were, between running and closed).
The issue is sometimes the app might have been exited and this white box doesn't appear. If the white box isn't present then the user can't close the application normally (by clicking the X in the top right). Likewise, if the app was exited and the user doesn't remember this when returning for their next session, they will naturally try to launch the application again. If the previous session was never actually closed it can cause issues with the newly opened session.
How do I restrict HoloLens from opening up a second instance of my Unity app, provided a session was previously opened and left either running or never closed?
Ideally if the app is already opened, when a user tries to open the app the HoloLens would refresh the previously existing instance and bring it to the users view or forcibly close the previous session before trying to open the new one (to avoid undesired behavior).
Is the best and most reliable way to handle this by enforcing a single instance of an Unity app on HoloLens? Or to detect if an instance is open and close that instance before trying to open the app again? Which, if either, is preferred or is it up to preference?
External resources I have found on this topic (a few of many):
How to determine if app is running on HoloLens - most relevant source of information I have found on the topic. Unfortunately it doesn't go into what to do with the affirmation that the app is open.
Unity Script Reference - WSA (Windows Store app) - again doesn't mention enforcing single running instance
Unity Script Reference - OnApplicationQuit - not sure if this is applicable to the situation but, there is a method Unity "sends to all game objects before the application is quit".
WIP:
private void App_Resuming(Object sender, Object e)
{
if (UnityEngine.VR.VRSettings.loadedDeviceName.Equals("HoloLens"))
{
UnityEngine.VR.VRDevice.SetTrackingSpaceType(UnityEngine.VR.TrackingSpaceType.Stationary);
UnityEngine.VR.InputTracking.Recenter();
UnityEngine.VR.VRDevice.SetTrackingSpaceType(UnityEngine.VR.TrackingSpaceType.RoomScale);
}
}
In the Initialize method (inside of 'App.cs')
public virtual void Initialize(CoreApplicationView applicationView)
Add
CoreApplication.Resuming += App_Resuming;
Can't test this at the moment as Hololens will connect to an network and spit out "No internet, connected" (tried both protected/unprotected networks). Device possibly needs an update, but we can't check for updates without a network connection.

For clarification, this is not a hololens specific question, where you need to look is in the windows 10 sdk, in windows 8 it was called tombstoning, its the act of moving away from an application without closing and being able to resume, Here is a link to an article about maintaining state in a windows 10 application, it's too long of a discussion and explanation to do it justice here.
https://visualstudiomagazine.com/articles/2015/09/01/its-universal.aspx
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/app-lifecycle#app-execution-state

Related

Google Play App Rejected-Special restrictions: Augmented Reality

We currently have an app on the app store that's been up for months now. Every release we've pushed has been approved just fine. The last vesion we tried to push we changed one thing and it was rejected and I am trying to figure out why. I know it has to do with augmented reality (which has also been in the app since the first release).
Here is what changed and our issue getting it approved.
The app was created with Unity3d. in previous releases you entered a login screen, logged in and were taken to a content selection screen in which the user selected which content they wanted to download and view. It then downloads the content. Everything here is fine. What changed was we noticed the analytics we were using for capturing how long the user was in the app was being reset because the permissions window that pops up when an AR scene is in use the first time calls OnApplicationPause. Our Analytics has an OnApplicationPause where if the user has the app paused (or just running in the background) it will end the current session and restart when the user brings back the app into focus. Because of this that popup messes with sessions. So we moved a check to determine if permissions were granted to the front of the app before they get to that content screen.
Because of this change Google has rejected the app pointing to the below policy:
Special restrictions:
If your app uses Augmented Reality, you must include a safety warning immediately upon launch of the AR section. The warning should contain the following:
An appropriate message about the importance of parental supervision.
A reminder to be aware of physical hazards in the real world (e.g., be aware of your surroundings).
So they are getting the same warning message about camera usage that they are then agreeing to its just not happening right when the AR camera is in use.
Can we just add our own message here? Does it have to be the permissions message in that scene only? I am not understanding if they are already aggreeing to those permssions why they would reject the app just because it isnt being displayed in that specific scene.
What is the best way to go about this?

How to make LAUNCHER activity be started instead of activity on top of activity stack after process is killed by OS?

Hi I have looked for this question and can’t find it, so here goes...
My application starts with a sign in activity which logs the user in. Upon successful authentication, the initial launcher activity is replaced by a ‘content’ activity.
Everything works fine until I place the app in the background via the home button and start up some memory consuming applications.
Upon returning to my app, Android tries to recreate the activity on the top of the activity stack, however what I’d like is to have the signin activity be restarted instead.
The reason being that the user needs to be reauthenticated again due to inactivity in communicating with the server.
Is there a way of specifying this behavior in the Manifest.xml file or programmatically?
I’m aware of save/restore activity state, but in this case I want the app to restart with the signin activity, thus bypassing needless restore. (Since the user will have to be signed in again due to inactivity)
Thanks for the help!
UPDATE:The issue arises solely when my application process is killed by Android to reclaim memory to be used by other apps that are being loaded. The only aspect of my app that still exists at that point is the activity stack and its top entry is my MainActivity. This is because the activity stack is NOT inside the app process.
So Android is attempting to be nice to the user and it tries to restore the state of my MainActivity. However my ability to authenticate against my server is gone at that point because the user’s credentials have been wiped from memory together with anything that used memory.
Therefore instead of attempting to restore my MainActivity under these conditions, I’d like my app to start at the activity which is designated as the LAUNCHER activity in the Manifest.xml file. This activity implements the signin process which gets credentials from the user and sets up various singletons whih are not tied to any specific activity. NOTE: I don’t want to persist credentials or cookies for various reasons, so that is not an option.

Monitoring regions but location icon disappears when app is killed

I have a CLLocationManager contained in a singleton and I have added around a dozen regions to monitor. I am successfully notified of boundary crossings when the app is in the foreground/background. However, when I force quit the app, the location icon disappears and I am not getting any callbacks.
As far as I can see, this is intended functionality as of iOS7. Here is a reply I found to a similar question, in this case involving significant location change: https://devforums.apple.com/message/882691#882691:
If a user swipes up in the app switcher then the OS will not launch the app unless explicitly told to do so by the user. So no, SLC will not be launching the app, nor will silent notifications. The only thing that will launch the app at that point is the user tapping the icon. The intention here is that the user has expressed their choice of not having that app running any more for any reason, so we honor that.
In this situation, there's really nothing that you can do. The next time the user launches the app you can let them know that some of the data may be missing, although you really cannot tell whether there's missing data or not (i.e. you might have been killed by the OS in the background and the user may not have moved thereby not triggering any SLC notifications). My suggestion would be to gather the data you can within the policies of the OS and if the user has manually killed the app then respect that wish and don't do anything.
By all means, feel free to file a bug report if this change in behavior winds up causing problems for you or (especially) confusion for your users.

Context for detecting earphones on iOS

I would like to detect when user unplug his earphones. It seems we can do this by using the audio route related functions as AudioSessionAddPropertyListener.
I have a question though:
Is it possible to use this both when application is open or running in background?
If yes, what happens if the user keeps the application running in background for a long time? Will I still be able to detect when user removes his earphones?

Opening one app from another app without closing the app

In the home page of my iphone app, there is a button added. When that button is clicked some other iphone app needs to be opened in a new viewcontroller (with out closing the parent app).There will be a back button on this view controller. When the back button is clicked, the new viewcontroller which is showing the another app needs to be closed and our parent app's home page needs to be shown.
Please give me some ideas on how to do this. I googled for this i didnt get any solutions.
Thanks,
Raja.
-- the following applies to iOS versions previous than 4.0 :)
Actually, there can be only one iPhone application running at once (with exceptions of Safari, Phone and some other system applications). The iPhone Human Interface Guidelines say so:
Only one iPhone application can run at a time, and third-party applications never run in the background. This means that when users switch to another application, answer the phone, or check their email, the application they were using quits.
However, if you only need to e.g. show a webpage, you can do it using UIWebView
Also, if you need to open another application, you should use URLs as pointed by Steve Harrison. This will, however, close your application. The recommended behavior in this case is to remember your application state and restore it when the application is run again, as Nithin writes.
According to apples documentation, they are not allowing any applications to be run in the background, except system generated ones. So you will be unable to do the thing you are going to implement. However, there is one thing that can make the same result.
You told that you are calling other application to run on a button click. Before initiating that application, save the current state of your application, may be using sqlite3 or core-data, and then open the other one. While returning back, load the pre-saved data from the database or wherever you have stored it. Every time you start the application, you check for the persisted data, if exists, load it or otherwise load your basic view
I don't think that you can run other iPhone apps within your own one. It doesn't make sense. You can open another iPhone app via a URL (see here and here), but this will close your app.
Like it has been stated: running two apps is not allowed by apple. You can however implement this apps features into you're app and have both get and save data to the same server...
Or like Nithin said: this functionality is available on JB iphones. Look into "backgrounder" for implementing one solution for normal users and one for thouse that has jailbroken.