简体   繁体   中英

How to get back to wp7 application after starting a web browser task?

In wp7 app I simply call web browser task. But when I press back button, it closes the task but also wp7 app. So, How do I go back to app ? (with back button or something else it doesn't matter.)

WebBrowserTask task = new WebBrowserTask();
task.Uri = new Uri("myUri", UriKind.RelativeOrAbsolute);
task.Show();

If you launch a WebBrowserTask from your app, the user will return to your app by default after closing the browser with the back button. It is possible that your code raises an exception when it is reactivated and then it crashes. To test this, simply run it with F5 and you will see if you get an exception.

Okay, when I asked the question, I had no clue about things in Windows phone 7.

So if you navigate to a new page or start new task(like web browser), then you click the back button, it goes back to the page which called the method(navigate or new task). There's no problem with it.

However, if an exception raises when navigating back, or going back to the app from task, the program crashes with Debugger.Stop() in App.xaml.cs .

I was using PhoneApplicationService.Current.State to store datas because I was passing these datas from page to page. But this way the app stores the datas only for the thread you are using.

Well, I had the problem because when I started a web browser task , the app deleted the datas I stored with PhoneApplicationService.Current.State . When I come back from the task, I was using the this code

string str = PhoneApplicationService.Current.State["some_key"];

But datas were already deleted, so it was trying to get the values, but couldn't achieve this, so it raised an exception.

This problem doesn't appear when navigating page to page, but when starting tasks.

So my suggestion is if you want to store datas, you could use IsolatedStorageSettings.ApplicationSettings . You can find a reference here .

It 'sa good approach, because not only you store the datas for the moment, you can use the datas when you open the app after closing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM