Preventing UWP from shutting down by pressing ‘B’ button on XBOX – XAMARIN - c#

There is a post in stackoverflow that covers my research in this matter so far: How to do job while the application is exiting in UWP?
I found this solution in several searches about the preventing UWP from closing and it works, I know I’ll have to ask for approval before I submit my app to Windows Store to use Restricted capabilities to use it, but it is ok.
But the point is: I’m writing an app to run in Android, iOS and UWP platforms, in UWP the ability of the user to close the app in a PC is quite alright but closing the app in XBOX by accidentally press button B in the Gamepad control is a very annoying issue that I want to prevent!
The post mentioned before cover the problem to UWP app in a pc, with is not an issue for me because if the user clicks the X in the up-right corner of the window it alright that the app closes, but if the user press B button of XBOX controller accidentally and the app closes immediately, it is a very rude event of user experience, and I want that out of my app.
So, the post I mentioned before works fine for a PC, but it does not work at all in an XBOX series S. My question is how can I solve this issue? I’m sure that is not a UFO thing because every game bought in the store have this issue solved!
How can I do the same?

I figure it out: preventing XBOX button B is about disable back button not about intercept a close request.
So, the only thing is needed to be done is to add:
protected override bool OnBackButtonPressed() => yes;
to the page where the back button is meant to be disables

Related

Windows Phone 8 resume/suspend /activated/deactivated

I am currently trying to make an app that takes some data from a server. I have a list and I am populating it when I login with some data. The idea is that that data can change over short periods of time. I made an auto refresh button, works fine, but I wanted to implement something like this:
When you open the app, everything loads, is good (done).
If you minimize (put in taskbar, I don't know how to say, enter on another app or menu). Your app will be suspended. When you resume it, I want it to perform the refresh thing. (Need help).
I'm currently working with Windows Phone 8, started project on this one and want to finish with this one. App.current. doesn't have resume or suspend, which I have found on lots of YouTube videos or on the MSDN site. Therefore I think I should do something with activated / deactivated, but I don't know where to add this handler. On the MSDN site I only found the function.
I am looking for something like this: Event on returning to app, after exiting by Windows key [UWP][Win10 Mobile], but as I told, I don't have this.suspend / this.resume on Windows Phone 8.
If we talk about Windows Phone 8, we have to specify which app flavor is intended.
For Silverlight apps, there are Application_Activated() and Application_Deactivated() methods, usually they're auto-created automatically in the App.xaml.cs
For so called "RT apps" there are events Suspending and Resuming, 1st one is subscribed automatically in the App.xaml.cs (so just put your code into that auto-generated handler), and you have to subscribe to 2nd one by yourself.

Is it possible to prevent my Windows Phone app from closing?

Is it possible to prevent my WP7 app from closing? I know how to override the back button, but is it possible to do the same for the start and search buttons? I am aware that preventing it from closing would cause it to fail certification, but this is a personal app that will not be submitted to the store.
Applications can override only Back button.
Both Search & Start buttons are not available for third-party applications.

How to delete delay on SendKeys.SendWait?

Hello I want to press a button with my app. So I use SendKeys class
SendKeys.SendWait("{RIGHT}");
Problem is that I need to wait 3-4 seconds after this line code for reaction from system. How can I speed it up or how can I delete this delay ?
// update 1
I've also tried
SendKeys.SendWait("{RIGHT}");
SendKeys.Flush();
BUt id didn't help
// update 2
I want my app that works in background to press a button programaticly in the actual active state of the user. So if he is in excel i want the right arrow to move the active cell, if he is in the game i want to turn right etc. SendWait does the thing I want but with some delay that I don't want.
Second important thing that this is not a virus or worm or anything like that. First of all as you can see I'm too stupid for that and secondly I'm playing with my KInect so this is some kind of interaction beetwen user and computer. Thats why it works in background and thats why I need to send it to the active app of the user
SendKeys is a nice little feature for Windows Form applications. Based on your tag it appears that you're using Windows Presentation Foundation, which will not support SendKeys.Send()
https://stackoverflow.com/a/1646568/340574
Take a look at the link above to use KeyEventArgs. I've read that you could also add a reference to System.Windows.Forms.dll through Visual Studio to use SendKeys, but I have not tried it myself.

Silverlight - First time going to Full Screen opens in background (FF, Chrome, not IE)

I have not found an answer to this, not here or when I have googled for it.
The case is that we have a silverlight with a video-stream. If we have enabled fullscreen with the code : Application.Current.Host.Content.IsFullScreen first time the application is taken to fullscreen it opens in the background (and for the customer it seems like nothing happens).
It seems it will remember it to the next time.
The alternative for our sake is to not enable it to disable this so that when the window loses focus it is taken out of fullscreen.
Is there a way to get around this, as we would both like to open it in fullscreen on top of the screen (not hidden), and have the possibility to make it pinned there. (Since many of our users would like to have it on another monitor and use the computer at the same time)
I have been thinking about storing it in application storage, as it seems it rememebers the first time a user move it in front. But dont know how this can be done, and also seems a bit hackish.
In IE this works, but of course this is not good enough.
To have your application stay fullscreen even when not focused, you have to add the following to your Application:
Host.Content.FullScreenOptions = System.Windows.Interop.FullScreenOptions.StaysFullScreenWhenUnfocused;
This will generate a prompt for permission when you switch to full screen mode, similar to IsolatedStorage quota prompts.
For the app showing in background, I only have experienced this using Safari on MacOS, I never had this issue on Windows IE, FF or Chrome. Maybe the line above will help matters though.

child controls disappear when running already running app

bit of a strange one... when my app is running I add a custom control to a StackPanel on the click of a button like so...
void btnAddPlayer_Click(object sender, EventArgs e)
{
PlayerControl sbItem = new PlayerControl();
ctlPanel.Children.Add(sbItem);
}
(ctlPanel is a StackPanel PlayerControl is a standard Control inherited from UserControl)
So I add one or two, not a problem... if I multi-task on the phone to a different app, then multi-task back to my app, not a problem... however, if I multi-task away (or hit the windows phone button) and then instead of multi-tasking back, I just click on the icon (as if Im running the app again) it reloads my app but without any PlayerControl's in the StackPanel ... and while debugging, it doesnt hit the InitializeComponents() method in the pages constructor (of course this could be because it might not debug it when you run it straight from the menu)
Anyone know if theres a way to only allow an app to be run once (and dont restart it if the user runs the app again)????
It does not work that way. You can save the "state" of your app and load that when you start the application. Look at "Tombstoning" for windows phones. Example, you can save in the local storage the current screen id and any other necessary data and when you launch the app, if you have something in local storage you load that screen, else you start with your homepage.

Categories

Resources