capturing dump on Windows Phone 8.1 - c#

I am developing a Windows Phone 8.1 app. I want to add a functionality that whenever the app crashes a memory dump is captured and written to a log.
I want to know if there is any way to log the crash dump while the user is using the app on his phone and it crashes. I found this question which is similar to mine but is for Windows 8. It says that we can use the 'Application_UnhandledException' method in App.xaml.cs to obtain the dump. But is this method supported in Windows Phone 8.1 too because I didn't see this in the auto-generated content of App.xaml.cs(which is generated by Visual Studio and contains functions like OnActivated, OnLaunched etc.)
Does the UnhandledException event handler do this thing in Windows Phone 8.1?

The Silverlight 8.1 App.xaml.cs class has an UnhandledException event handler just like 8.0.
WinRT 8.1 apps on the other hand require you to add the handler yourself.
To do this, go to App.xaml.cs and in the constructor, add the following:
this.UnhandledException += App_UnhandledException;
Also add this event handler:
private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Save the dump here.
}

Do you require explicit dump handling on your own? If you publish through Store you should already be able to access "dumps" (more like stack-traces) from your Store accounts quality page.
http://msdn.microsoft.com/en-us/library/windows/apps/hh967782.aspx
http://blogs.msdn.com/b/windowsstore/archive/2012/06/27/improving-apps-with-quality-reports.aspx

Related

Catch a link click with a certain pattern in Windows Runtime

I am developing an app based on a mobile website which runs inside a Windows Runtime WebView for Windows Phone 8.1. Currently, I am looking for a way to catch link clicks in the app's webview which start with a certain pattern. In the Windows Phone Silverlight version, the following was possible:
In my webview I display links like this
Do something in the app
Do something different in the app
In the app, I catch a click on such a link with the following code
MyWebView.Navigating += HandleOwnStuff;
void HandleOwnStuff(object sender, NavigatingEventArgs e) {
String url = e.Uri.ToString();
if(url.StartsWith("ownstuff:")) {
// check which function has been called and do something in the app, e.g. open the camera
}
}
Unfortunately, this approach is not possible in a WinRT app any more. Whenever I click such a link, the launcher opens with the message "Search for an app in the store".
The "NavigationCompleted" handler of the WebView is not called - this link click is catched before any handler of the WebView is called.
An approach which would work is using the UnsupportedUriSchemeIdentified handler, which - unfortunately - is only available starting from Windows 10 in UWP.
Another solution would be to completely rewrite my website so that the ScriptNotify handler can be invoked - which would be way too much work, since the website now also runs in normal browsers, Android and iOS devices - so this approach is definitely not worth the trouble.
Does anyone know a solution? Thanks.
I have talked about this with MSFT for awhile. Your right, with win10 that's why that event was added. The best way to workaround it is to change the website.

How to know the app suspension reason in WinRT app?

In my Universal app, (Windows 8.1 Windows Phone8.1), I want to know the reason why my app is suspended like due to a launch of a launcher(Mail, File picker etc) or user pressed the Windows button. Is there a way to determine this?
Unfortunately you can't know what caused the app's suspension. Unlike the LaunchActivatedEventArgs in the OnLaunched method for example, that contain the Kind property the SuspendingEventArgs in the OnSuspending method don't provide any such information.
However, there are only so many reasons that an app can be suspended. Like you said (in windows phone only) it can be suspended due to a launch of a launcher or a protocol and by the windows button.
The windows button is the only suspension way of which you have no control. For all the others you can trick the system and for example set a static global variable that you update when you launch an operation that would suspend your app and check it in OnSuspending

How to close a Windows Phone 8.1 app

In WP7 and WP8 I just needed to clear the backstack in a page, then press Back button and the app is closed. In WP8.1 I do Frame.BackStack.Clear(), press Back and the app just minimizes.. How to kill it with Back button?
You can add, in your main page definition:
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
Then
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
if (!e.Handled && Frame.CurrentSourcePageType.FullName == "YourApp.MainPage")
Application.Current.Exit();
}
Warning: As others said, you should not use this and let the system handle the app closure. For example, if you use the Application Insights, I found that they are not sent to Azure when in Release mode
I think the above has been depreceated. Exit is now an event.
Try
Application.Current.Terminate();
you can simply create a button by using XAML and then add this code into your Main page xaml.cs
Application.Current.Exit();
MSDN recommends to not close apps in Windows 8.1:
We recommend that apps not close themselves programmatically unless
absolutely necessary. For example, if an app detects a memory leak, it
can close itself to ensure the security of the user's personal data.
When you close an app programmatically, the system treats this as an
app crash.
https://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx#close

Detecting deactivation and app close in Windows Phone 8.1 XAML

For security reasons, I need to log out the users when they exit the app and show login screen when they return back.
In Windows Phone 8 and Windows Phone 8.1 Silverlight there are Application_Deactivated and Application_Closing methods on the App class (or methods OnClose, OnDeactivate to override in Caliburn.Micro).
The only interesting events seems to be Suspend and Resume, but they do not called when I exit the app using the Start button and get back using the Back button or launching the app from the list.
What are the alternatives for Windows Phone 8.1 XAML?
(Setting ActivationPolicy="Replace" would solve half of the problem but I guess this is not possible, when WMAppManifest.xml is not event a part of a Windows Phone 8.1 XAML project).
The Suspending event will be called just after you navigate away from the app, but not in debug mode. I've build a simple app modyfing LocalSettings upon Suspending event and then acquiring information when Resuming.
You are probably aware, but for the sake of completeness of the answer - some remarks:
before Suspending event, the OnNavigatedFrom event is being called, but when you Resume, the OnNavigatedTo is not called - reference:
Note On Windows Phone, OnNavigatedFrom() is called when the app is suspended. OnNavigatedTo() is not called when the app is resumed.
to test Suspending/Resuming with debugger, use Lifecycle events in Debug location tab - more info
reference to Application lifecycle in Windows Runtime apps

Execute code when exiting Windows 8.1 App

I'm attempting to execute some code on my Windows 8.1 app on exit, when a user drags the app down normally (not the extended hold to terminate).
In Windows 8, I used the following code to clear the app's tile on exit:-
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Clear();
}
However, this code isn't called in Windows 8.1 when the way the app terminate changes.
How do I recreate my code for Windows 8.1?
In 8.1, the close gesture no longer kills the app. Instead you have to hold it at the button for 1 second and when the icons flips, the app is closed.
Look if the code is executed there.

Categories