1

WP7 newbie here..
In my application, I am using embedded web browser control to load an external web page.

I have a PIN based validation step in that application, which involves
1) User Leaving the current application, (which has a external web page loaded in the embedded web browser) to launch the SMS Inbox.
2) User reads the SMS he just received, which has the PIN. I am sending this SMS to the user.
3) The User then needs to resume back to the original application by hitting back button, to enter the PIN which he received in the SMS earlier.

Once user enters Step2, my application will go into background, and subsequently will get tombstoned. Once user enter Step3, I want to restore application state (with the embedded web browser control), without making a fresh HTTP request again to load the web page.

So, with the given scenario in my mind, I have following two questions -
1) Is there a better way to do all this, like not having to exit the original application, and still let user read the SMS. ( i.e any api to read sms ?)
2) Is there a way to serialize the browser state/save entire web page (with images, css, js) , such that entire web page can be rendered exactly the way it was, when user left the running application.

Important points:
1) I can only use SMS as a communication channel. I can not use something like raw push notification channel, which could let me show PIN to the user, without exiting the application.
2) I am targeting Windows phone 7.0 runtime, but if there is a better option available in Windows Mango update, please do tell me.

Any sort of help is greatly appreciated.

Update: Added link to the embedded web browser component.

Ashish
  • 430
  • 7
  • 13

2 Answers2

2

1) There is no API that would let you access the contents of the Messaging hub from inside your application. This is set up for privacy purposes.

2) By default, the web browser saves its state. So if you navigate away from your app, and then come back - the same web page will still be there unless you explicitly re-navigate on activation

Den
  • 16,686
  • 4
  • 47
  • 87
  • Thanks for the reply @Dennis. About 2), So what code should be executed when NavigatedTo event gets called for the page having the embedded browser, automatically on application resume. Also, I tested your approach by keeping track of application state in a variable, and not executing any code (in Loaded, navigatedTo event handler) when application resumes. Embedded Web browser doesn't show any page at all in that case. – Ashish Aug 09 '11 at 07:54
  • Do you execute any code on activation? http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated(VS.92).aspx – Den Aug 09 '11 at 15:58
  • This is the basic POC code I wrote to test if Approach 2) works, as you pointed out. Can you please point out if I am doing something wrong or missing something. - http://pastebin.com/UgwCheem. – Ashish Aug 09 '11 at 16:28
  • You are explicitly invoking the Navigate method for the WebBrowser control. You shouldn't do that in your case. – Den Aug 09 '11 at 16:32
  • Yeah, but that code is only executed the first time the browser loads. That line won't be executed when application resumes again, as I am setting "repeated" flag in Application_Deactivated event handler, when application gets deactivated. – Ashish Aug 09 '11 at 16:39
  • I specifically tested this behavior on several physical devices as well as in the emulator - the page persists in the browser even when I navigate away from the app itself. What web page are you trying to open? – Den Aug 09 '11 at 16:52
  • it can be any external web page (like www.google.com for example). If I don't execute any code at all, then the embedded browser component at the page comes as blank for me. BTW, the comment section is getting a bit crowded here. Would it be possible for us to chat in the stack overflow chat room here - http://chat.stackoverflow.com/rooms/2289/discussion-between-ashish-and-dennis-delimarsky – Ashish Aug 09 '11 at 17:25
1

1) The better way to do this would be to not embed the web page within an app. Just build a mobile website. If all the functionality is within the web page you gain nothing but problems by trying to put it inside an app.

The web browser control is not intended to be used to create an alternative browser (which is really what you're doing).

2) You can try using the SaveToString() method to store the state of the page when tombstoned but this doesn't allow for modifications to the page since it was loaded (including anything dynamically updated or any state in javascript). If you have multiple pages you'll also need to maintain the internal backstack and the state of each page separately.

Short answer: If you want to put your application logic in a webBrowser control then you can't support tombstoning. Fast-App-Switching (in Mango) partially addresses this but not completely.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143