Windows Phone 8, minimize app - windows-phone-8

Have a broblem with minimize application, when back button pressed:
protected override void OnBackKeyPress(CancelEventArgs e)
{
}
I need do not close application, just minimize him to background, have any idea for this?

You should close on back - otherwise you will fail certification for the store. If you need a background task running, instead use a Background Agent

More precise:
You can activate fast resume in the manifest:
http://msdn.microsoft.com/en-us/library/windows/apps/jj735579(v=vs.105).aspx
This will keep the instance of your app in the memory until the system cleans up the oldest apps to free memory when needed.
This is the recommended behavior and the default for all 8.1 Runtime Apps.
Hint:
Once put to the background, you app will still be suspended and no longer active.
It will be resumed once it gets back to the foreground.

Related

Can't Unlock Windows IOT Process after Debug

Trying to debug a Universal Windows app (MyTest) for Windows IOT using Local Machine. It starts the app but only displays the X screen, not my MainPage.xaml. OK, probably some bug I made. But I can't debug it and I can't unlock it. I try to put a breakpoint at App() constructor or OnLaunched and it never hits. If I Stop Debugging the X window stays up. Worse, if I kill the X window, using the window close (button in the top right), the app looks like it stops but the MyTest.exe remains locked, forever stopping me from trying to delete the exe, rebuild project, etc.
There is no MyTest app in the TaskManager (processes or details).
If I terminate ApplicationFrameHost process, the X screen will go away, but the MyTest.exe file remains locked as though the exe is still in use.
I've tried FileAssassin and it can't remove the lock.
The only thing that unlocks MyTest.exe is rebooting the machine...kind of a pain if you only get 1 debug run before rebooting the machine each time!
if you are using tasks you must terminate all.
example
BackgroundTaskDeferral _defferal;
public void Run(IBackgroundTaskInstance taskInstance)
{
_defferal = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
}
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
//a few reasons that you may be interested in.
switch (reason)
{
case BackgroundTaskCancellationReason.Abort:
//app unregistered background task (amoung other reasons).
break;
case BackgroundTaskCancellationReason.Terminating:
//system shutdown
break;
case BackgroundTaskCancellationReason.ConditionLoss:
break;
case BackgroundTaskCancellationReason.SystemPolicy:
break;
}
_defferal.Complete();
}
source: Windows 10 IOT Lifecycle (or: how to property terminate a background application)

ApplicationClose event

I'm developing Windows 10 universal app in C#/XAML.
I want to implement such a policy, that whenever user closes my app (and some other conditions are met, but its irrelevent here) an adverisment will display.
My question is how can I intercept and cancel/handle an event when application is being closed? This is easy when user decides to close the app by for example pressing a button that I'll define in XAML, but what if he presses Alt+F4? In Winforms this is easy as well:
private void Form1_Load(object sender, EventArgs e)
{
this.FormClosing += Form1_FormClosing;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
But how can I achieve similiar effect in in Windows 10 universal app?
I'm afraid there is no option to cancel the closing of the app or even delay it. The Suspending event is the only indication your app will receive prior to termination (if it happens). Check out the Application.Suspending event: https://msdn.microsoft.com/en-us/library/windows.ui.xaml.application.suspending.aspx
No, you can not achieve the similar effect in Windows 10 Universal App (and Windows 8.1 Store App), because in the modern app, the user have the full control of the app and the app can not stop the user closing a app.
If you have sth need to handle when user closing the application, as Lukkha stated, you can handle them in Application.Suspending, but there is a time limitation by default, all of the things should be done within 5s. If you want to have more than 5s, you need to request a ExtendedExecutionSession.
Using Extended Execution in Windows 10 Universal Apps

How to avoid the screen to lock while the Windows Phone is plugged in

Easy as that, in android there's a setting called Stay awake that will prevent your phone to lock down while you're using it for debugging an app.
I'm looking for the same thing (could be better) for Windows Phone 8.1.
Every time I hit F5 I need to unlock my phone or I would get the following error:
DEP6600 : Deployment failed. Cannot deploy app when device screen is locked. Please make sure that the device screen is not locked, and try again.
or
Error: Application launch failed. Ensure that the device screen is unlocked and device is developer unlocked. For details on developer unlock, visit http://go.microsoft.com/fwlink/?LinkId=195284
if I run the AppDeployCmd tool myself.
Is there a way I can avoid that? (without changing my lock screen time out every time of course)
I don't think you can do this without writing a separate app. On the phone there is an option: Settings > Lock Screen > Screen time out, which you can set to maximum available. For same phones, like lower end Nokias there is an option to set that time to never, however for newer phones such as Nokia 1320 or Nokia 1520 that maximum is only 5 minutes.
I think it isn't possible, but here is an alternative
EDIT: You can write an separate app, wich you should run while you're developing other apps. This app must consist of this lines code.
DisplayRequest AppDisplayRequest = new DisplayRequest();
public MainPage()
{
AppDisplayRequest.RequestActive();
}
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
AppDisplayRequest.RequestRelease();
e.Handled = true;
Windows.Phone.UI.Input.HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
Application.Current.Exit();
}
The resolution for the error DEP6600 should be there in the code itself instead of writing a separate app. how can this be done. in other words, the moment my app is compiled build and after deployment the error shouldn't come and the app should run even when the phone is locked

Using App.Current.Terminate() method in Windows phone 8

As windows phone 8 provides us with this method for programmatically terminate an app, will there be any issue while app submission if we use this in app for terminating a page while there is no backentry in the navigation history?
There won't be any issue in certification when using this call, but make sure you have saved all data in your app when calling this, because this call effectively kills your app immediately - ApplicationClosing even handler won't be raised after it!
Why would you call Application.Terminate when navigating back with an empty back stack? Just let the app close itself. Seems a bit pointless to me to overuse Application.Terminate().
I can't say much about the new Terminate method, but I do have an app (NOTE: Not a game) that does the following at certain points
private void Kill()
{
new Microsoft.Xna.Framework.Game().Exit();
}
This app passed certification without any problems. This was an app for both WP7 and WP8 so I did not have the ability to use Terminate().

Is it possible to know whether Windows widget totally covered by other windows?

We want to create a Windows desktop version of our weather widget
There are 2 special things about the widget.
It consumes a lot of processor time
while active - it displays an
animated picture (Flash without GPU acceleration, unfortunately).
It updates the weather from our
server (frequent server requests from all widget users).
When the user does not look at the widget there is no need for animation and weather loading.
So I have an idea of putting my widget to sleep when it is not visible and hense not used.
Is it possible to detect whether the widget is used or not.
Speaking precisely I need to know whether the widget is covered by other windows?
I mostly interested in Vista/7 gadgets engine, however I also would like to know if this problem is solved in these widget engines
Yahoo widgets
Google desktop
Hope to find some desktop widget guru here.
Pasha
If you InvalidateRect and don't get a subsequent WM_PAINT message, than your window is hidden. You can call UpdateWindow after InvalidateRect to force the WM_PAINT message to happen (or not happen) right away.
So you could do something like this
request server data (and cancel request timer if any)
when data arrives InvalidateRect
when WM_PAINT message arrives, draw the data and set a timer for next request
when timer arrives, goto 1
When you stop getting WM_PAINT messages, you stop re-setting your timer, and you therefor stop requesting updates from the server. When the WM_PAINT message happens (because you are no longer covered). You start requesting data again.