Minimized Hololens application stops recognize air-taps.
It happens when you've let the app go idle for a while and then try to restart your session.
the gaze will turn into a doughnut but it won't do anything when you air tap.
void OnApplicationPause(bool paused)
{
if (!paused)
{
GestureListener.Instance.OnDisable();
GestureListener.Instance.OnEnable();
}
}
I do this each time I invoke app but it doesn't help.
Related
Looking for some feature that can make my app start up even fast, I found the prelaunch feature in the Microsoft documentation that would help open the app faster. But even if I register the app to enable prelaunch, the OnLaunched event keeps getting false in e.PrelaunchActivated.
(I only could test this feature using the VS option 'Debug UWP Prelaunch' in debug mode).
Do I need a Microsoft certificate to use it?
How long does the OS take to understand that my app is eligible to prelaunch?
Does this influence the fact that I'm getting false at the event?
I made a test and the prelaunch works correctly. I'll post my code here and explain how the prelaunch works. Hope it will help you solve your question.
Here is the sample code that I used:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
bool canEnablePrelaunch = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch");
// ********
// some other code here
// *********
//check if it is prelaunched
if (e.PrelaunchActivated == false)
{
// On Windows 10 version 1607 or later, this code signals that this app wants to participate in prelaunch
if (canEnablePrelaunch)
{
TryEnablePrelaunch();
}
// ******
// normal code
// ******
}
else
{
//prelaunched
// do some logic that don't require UI thread.
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), "PreLaunched");
}
// Ensure the current window is active
Window.Current.Activate();
}
}
As you could see, I add an else sentence to do the work when the app is prelaunched.
When testing via the Debug Universal Windows App Prelaunch mode in Visual Studio, the whole process should be like:
Choose the Debug Universal Windows App Prelaunch mode, then the app will be prelaunched.
The OnLaunched event will be fired and you will go into the else sentence because it is prelaunched.
You could do your work in the OnLaunched event for prelaunched
Then the app will go to suspend status.
Now, the user launches the app from Start Menu.
The OnLaunched event will be fired again and this time it will show e.PrelaunchActivated == false because it is launched by the user, it is not prelaunched. I suspect this is the behavior that you are getting.
So this is the whole process about how the prelaunch works. This is also mentioned here: App launch.
In my case, Windows does not use Prelaunch when app is deployed by Visual Studio, but after installing it from the Store it works as expected. User must run an app at least one time and next time you will see it in the Task Manager. Will it work or not, depends on the amount of available memory, but I found it working even on a device with 4Gb of RAM.
I have a IOS app which show product details and for the AR section it opens another unity app.What I want to do is Quit the Unity app and go back to same page in the main app.I have used the following code.
public void BackHome()
{
Application.Quit();
}
The problem with this code is it quits like termination not smooth closing of app.Also it goes directly to the Home screen not to the app (that is main app page from where the Unity App opened up).What I want to do is open Unity app from the main app and after that while hitting a back button would like to close the unity app and return to the main app.
In player setting in Unity I have given Behaviour in BackGround - Exit.
Before Application.Quit, try open main app by URLSCHEME: Application.OpenURL("XXXXXX").
How should I "properly" programmatically terminate a Windows Phone 8.1 app?
Application.Current.Exit (); doesn't work. My code continues right through it.
Here's the snippet:
public static async Task ShowAndGo (String MessCode, String MessText, Boolean Xit)
{
String Mess = ""; // Start out with an empty Message to tell Joe User.
String Title = ""; // And an empty title too.
MessageDialog messageDialog = new MessageDialog (Mess, Title);
await messageDialog.ShowAsync (); // Stop and wait for user to acknowledge.
if (!Xit) // We're done here if we're not goin' down.
return;
//
// If we're goin' down,
// we have a lot of cleanup to do.
//
Application.Current.Exit (); // This should stop us. But it doesn't.
}
How should I "properly" programmatically terminate a Windows Phone 8.1 app?
The short: There isn't a "proper" way, and it's recommend that you shouldn't
The remarks on the Application.Exit method states:
Normally, however, you should not provide this UI because the system automatically manages app lifetime and terminates suspended apps as needed to free resources.
The guidelines say you should:
Design your app to suspend when the user switches away from it and resume when the user switches back to it.
Don't terminate the app when the user navigates away from the app or closes the app using the close button. The operating system ensures that there is a consistent way for the user to access and manage apps. Your app is suspended when it is no longer visible to the user. By leaving the application lifecycle to the system, you ensure that your user can return to your app as efficiently as possible. Doing so also provides the best system performance and battery life from the device.
Rather register an event handler for the Suspending event.
It is called when the app is suspended. You can use this event handler to save relevant application and user data to persistent storage.
It is good to read the Application Lifecycle page.
How to programmatically terminate a Windows Phone 8.1 app?
Windows Phone 8.1
Application.Current.Exit();
Windows Phone 8.1 (Silverlight)
Application.Current.Terminate();
Your code
I used your code as is for testing, and it worked as expected when I remove:
if (!Xit) // We're done here if we're not goin' down.
return;
Xit is never assigned in your code sample; if Xit is false then the termination line will not be reached. Just remember that bool values are false by default (if no value is given to them)
Try using Application.Current.Terminate(); instead of Application.Current.Exit ();
For example
private void Exit_Button(object sender, System.Windows.Input.GestureEventArgs e)
{
Application.Current.Terminate();
}
I'm using a Modal Loader in a WPF Application to indicates to the user some background processing.
All works fine with keyboard and mouse, but when it runs in a Windows tablet the application freezes executing this procedure:
public void Complete(bool focusOnWhoCall = true)
{
try
{
Dispatcher.InvokeShutdown();
}
catch { }
}
Running with the remote debugger, when froze, I pause the running. The visual studio execution pointer is on InvokeShutdown. Then I continue and it executes... It keeps freezed... I pause again and it stopped in the same point.
I uploaded this video on youtube to show the problem: https://youtu.be/IryEJ-YF168
I start using the mouse. All fine. When I use the touch at the first time its freezes... I don't know what to do anymore...
I make a project sample, every can download here: https://onedrive.live.com/redir?resid=F4B7C28FAD05ECCD!3743&authkey=!AHs6dcCjRGJmB4c&ithint=file%2czip
Thank's in advance!
When the BackgroundAudioTask for my app is cancelled by other app on Windows Phone 8.1 which also uses BackgroundAudioTask, when I go back into my app, it will no longer play audio in the background. It will play fine when the app is running but if it is suspended - the background audio also stops.
The steps to reproduce this issue are:
I launch the Windows Phone 8.1 app which has a BackgroundAudioTask & everything works fine. I that start another app, for example the Music player, that uses a BackgroundAudioTask it will cancel the BackgroundAudioTask of my app.
When I launch my app for the second time, I want to re-register my BackgroundAudioTask so that it will behave as it did originally.
In Package.appxmanifest I have the following:
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="WindowsPhoneBackgroundAudioTask.BackgroundAudioTask">
<BackgroundTasks>
<Task Type="audio" />
</BackgroundTasks>
</Extension>
</Extensions>
When I first run the application the Run method will be called and I add a Deferral to the task to make sure it is kept alive even when I close my application:
public void Run(IBackgroundTaskInstance taskInstance)
{
setupDeferral = taskInstance.GetDeferral();
}
When I start the music player from another application my BackgroundAudioTask Cancelled event is called (If I don't do setupDeferral.Complete() here my application will crash):
private void Task_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
setupDeferral.Complete();
}
When I open my app how do I recreate my BackgroundAudioTask? The problem is the Run method is never called again so I can't setup the Deferral again. Music will now play fine in the app, but as soon as I navigate away from the app the music will stop.
I tried manually re-registering the task in App.xaml.cs in the App_Resuming event with this code:
var taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "BackgroundAudioTask";
taskBuilder.TaskEntryPoint = typeof(WindowsPhoneBackgroundAudioTask.BackgroundAudioTask).FullName;
BackgroundTaskRegistration task = taskBuilder.Register();
The above code will throw and InvalidArgumentException because it does not have a Trigger setup. I don't want it to have a trigger. I just want to start the background task immediately.
Is there a way to manually instruct the OS to run the background audio again or a way to handle cancelled background audio better?
I know this is really old - but maybe someone will come across it. You actually don't need to register the task at all.
In the case of background audio, all you need to do is call
BackgroundMediaPlayer.Current
And it will fire up the task, and then your code will get the deferral.
I too had this same issue. The Background Audio Task wasn't starting playback once it was cancelled - either due to 5 minutes of inactivity, or due to another app. I was referring the sample code given by Microsoft here.
After hours of searching on the internet, I didn't find a solution. Then, digging in my code further, I found out that when the task is cancelled, the BackgroundMediaPlayer.Current.CurrentState becomes MediaPlayerState.Closed.
Hence, in order to restart the task/background audio playback, just set a source to the BackgroundMediaPlayer.Current again. In the sample code, this media player object is referenced using a variable named mediaPlayer inside the PlaylistManager project component.
Although the sample has a piece of code to restart playback once the task is cancelled, it does not work.