Windows phone: close the app after click on a button - windows-phone-7

How can I close my app after a button click? I mean in:
private void chiudi_app(object sender, RoutedEventArgs e){
}
I've tried a lot of things founded around the web (like Application.Exit() and other things), but without success.

In WP7 there is no API to exit your app. But you can create an ExitException
public class ExitException :Exception {}
and throw it where ever you want to quit.
throw new ExitException();

Related

Windows Universal App Open webbrowser with link

I am making an universal app and when i click a certain button, i need to open the webbrowser with a link. I got the link as a string in a variable but the windows 7 / 8 app ways such as "Proces" and Webbrowser objects give errors.
In windows apps, you can't simply open other apps/programms.
The only posibility is to use the Launcher:
Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.google.de"));
The Launcher looks up the default program/app which is assosiated to the uri-scheme (in this case "http://" for webbrowsers) and forwards this call
others then above you can go Package.app manifest change the start page to the URL that you want or another method by using web control set the source to the URL you needed.
use scope async, it will open link to the mobile,PC default default browser for UWP
private async void Button_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.fmradiotune.blogspot.com"));
}

Getting AppID for Windows Phone in Unity3d

I am developing game for windows phone in unity3d, I have inserted Rate me button in game but on run time in windows phone it didn't work, is there any method to access AppID for the current application running in windows phone developed in Unity3d. I need code in unity3d CSharp for getting AppID.
I tried this C# code in Unity but It didn't work and having error no keywork found windows.
string appId = Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
LinkUri = new Uri("http://www.windowsphone.com/s?appid=" + appId, UriKind.Absolute)
Here I needed AppID to complete my link for rate me.
As far as i know Unity can not access the Windows namespace but you can make use of EventHandler to call 'Review Task' from Unity. You can do this by following below steps(visit Unity Expert for detailed explanation).
In Unity Game Engine-
Create Event -
using UnityEngine;
using System;
public static class events
{
//Create a new event
public static event EventHandler RateUs;
public static void FireRateUs()
{
Debug.Log ("Opening Rate Task......");
//If event is subscribed than fire it
if(RateUs!=null)
RateUs(null,null);
}
}
Fire Event -
using UnityEngine;
public class RateUs : MonoBehaviour
{
void OnMouseDown()
{
events.FireRateUs();
}
}
In Visual Studio IDE
Subscribe Event -
public MainPage()
{
.
.
.
.
events.RateUs += events_RateUs;
}
Call Function -
void events_RateUs(object sender, EventArgs e)
{
String AppId = Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid=" + AppId));
}
You have to get your AppID from your developer's portal on Microsoft Create's web page. You can then hardcode it into your app or save it as a static/globally available variable for accessing purposes. This would mean you would have to begin the process of creating your app entry prior to the programming of the rating game feature. Just create the entry, and don't submit it! Or create it, and add Rate app as an update. I'd choose the former method, personally!
For Apple and Google rating/submit information you have to create the entry ahead of time to get a SKU number. Also in iTunes/Apple/iOS/OSX you have to create the app and give it a unique name, etc in the developer's portal/certificate store.

How can i use NavigationServices in Application_Activated windows phone 7?

im developin an app for wp7 that it holds pictures and notes with password login. But when app running if user press windows button app is running at background and if user press back button it resumes without asking password again.
i tried to Navigate when app activated but i couldnt manage it in Application_Activated method. is there a way to do that? Or could you advice me sth else that solve my problem.
ty.
here is my code im using to navigate,
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
I got around this issue by using UserControls on the MainPage, showing one if the user had not yet logged in and the other if they had, I set these controls up to show/hide based on certains states in the MainPage and then bind that to the MainViewModel:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
....your code here to load stuff...
App.ViewModel.MainPageState = "ShowThemTheLogin";
}
}

How to go to main menu on a button click in WP7

I have a button in the main page and on the click of it i want to exit the app and return to the phone's main menu page. My concern is that i cannot use CancelEventArgs for button_click event and another concern is that this is the first page in theNavigation stack, so Navigetion.goBack is false. Suggestions and help are welcome.
private void btnDeclineClick(object sender,RoutedEventArgs e)
{
exitApplication();
}
public void exitApplication()
{
try
{
NavigationService.CanGoBack.Equals(true);
if (NavigationService.CanGoBack)
{
NavigationService.GoBack();
}
}
catch(Exception e)
{
Logger.log(TAG, e.Message);
}
}
Programmatically exiting the application is not supported and against the certification requirements. I agre with Praetorian that you should just not have a Decline button or have it simply cover the application UI with some non-interactive content.
The only supported mechanisms for exiting the application are for the user to press the back button or navigating forward out of the application using the home/windows button or any launcher and then being killed by the OS.
Is this are you facing problem of exiting application programmatically ??
If yes you can do that without worrying which page user into currently
For exiting programmatically you can check this my another post answer.

Timer and saving its state

I am building a windows phone application (basically its a game but I am not using XNA, Silverlight was enough). The graphics are moving based on a DispatcherTimer. What I want to do is basically stop the timer whenever a call arrives on the phone, and start it again after the call has finished, so that the game state is not lost.
I tried with :
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
Game.timer.Start();
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
Game.timer.Stop();
}
but it did not work, it actually does not reach to this point when a call arrives at the phone. Anyone had such experience?
Thanks in advance :)
When a call is received you will receieve the Obscured Event on the Frame.
Please note that this event can also be fired for more than just a received phone call though.

Resources