child controls disappear when running already running app - c#

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.

Related

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

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

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.

Windows 8 metro app works properly on Visual Studio but not on tablet

I am developing a Windows 8 metro app where the main screen just has a button. On clicking the button, the app navigates to another frame where all the work is done (which includes reading from files in local storage).
The app works perfectly when I hit run on local machine from Visual Studio 2013. However, if I try running it from the start menu, the main screen opens, but clicking the start button does not cause the app to navigate to the 2nd frame.
*This app was working fine (even when I ran it from start menu) for the last month. I changed some code (things that happen in the 2nd frame and should not affect main screen) and now I am having this issue.
*I am pretty sure that clicking the 'start' button causes the code on the 2nd frame to run,even though it appears to do nothing. I suspect this because if the file that is to be read in the 2nd frame is not in the directory, the app crashes.
I would greatly appreciate any help. I am pretty new to this and am not even sure how to debug an application that's not being run from an IDE.

Stop processing if application window is totally obscured

I am developing a WPF application when the application is shown a thread work
and show a refreshed data on the application ui .
for saving performances i want to stop this Thread if the application is 100% covered by another application .
for example if the user is using another application that take the right half of the screen ,and my app is shown on the left half of the screen , the app must steel works cause the user is using the other app and watching the
changed data on my app .
if the application is back grounded or 100% covered by another app window or
minimized must stops;
i tried many solution like using the Deactivation event of the window
and p invoke but that not resolve the situation.
and thanks you.

Detect between app start up and returning from another page

I am building a win 8 metro app. In my main page, I have to check settings when my app starts up. But if I navigate to another page and come back , I do not want it to execute again. How can I detect this?
If you want to do something once when the app is launched, use the Application.OnLaunched method. It is already implemented in the App.xaml.cs and you can add your code there.

Categories

Resources