Tag Archives: Offline Browser

Windows-Phone-7-logo

Another way to close Windows Phone application from code


Correction

In my previous post on how to terminate the Windows Phone application i proposed a solution that is not really in accordance with Windows Phone Marketplace Technical Cerification Requirements (see requirement 5.1.2):

” An application that closes unexpectedly fails certification. ”

Even though I’m pretty sure that this requirement is not enforced since my apps use this approach and they were never rejected i decided to present another way.

Some good people suggested in comments of my previous post that you can terminate current application  simply by calling the XNA Game class Exit method like this:

using Microsoft.Xna.Framework;

namespace Roboblob
{
    public class AppLifetimeHelper
    {
        public void CloseApplication()
        {
            new Game().Exit();
        }
    }
}

The downside of this is that you need to add 2 XNA dll’s to your project:

  1. Microsoft.Xna.Framework
  2. Microsoft.Xna.Framework.Game
So there you have both approaches and you can choose which one is better for you until Microsoft exposes standardized way of closing application from code (i hope this will happen in Windows Phone 8 APIs).

Windows-Phone-7-logo

How to terminate your Windows Phone application programmatically?


21/08/2012 Update: 

There is another way to close the Windows Phone application without throwing exception see more details in my next post.

We want full power!

Its known that in Windows Phone API there is no easy way to terminate the current application from your code.

I guess makers of the platform did not wanted us developers to mingle with the application lifetime too much, phone should decide when an app is not needed and terminate it.

But i just simply cannot help myself, i always like to have full control, for example in my Offline Browser application i want to end the app if user presses the hardware Back Key multiple times in short time intervals.

Because there is this annoying situation when user goes navigating between the pages in your app (main screen, then settings, then about screen,

then again main screen etc) and then when he wants to terminate it he need to click the hardware back button N number of times in order to close it.

And even in some other situations its needed to force close the app, for example if some change in application settings requires app restart etc.

Show Us The Code!

So i decided to change this and wrote this simple AppLifetimeHelper that allows you to terminate your current app without any delay.

How it works is that it uses Application.Current.RootVisual and casts it to PhoneApplicationFrame that has RemoveBackEntry method that basically simulates

the users hardware Back Key press and then in endless loop it calls this method until the navigation back stack of the app is empty.

Then all we need to do is to call the GoBack method of the PhoneApplicationFrame and it will terminate the app since there are no more entries in the app Back Stack.

Simple or what?   8-)

So here is the code if you AppLifetimeHelper that you can freely use in your apps if you need this functionality:


using System.Linq;
using System.Windows;
using Microsoft.Phone.Controls;

namespace Roboblob
{
    public class AppLifetimeHelper
    {
        public void CloseApplication()
        {
            ClearApplicationNavigationBackStack();
            Root.GoBack();
        }

        private PhoneApplicationFrame _root;
        private PhoneApplicationFrame Root
        {
            get
            {
                if (_root == null)
                {
                    _root = Application.Current.RootVisual as PhoneApplicationFrame;
                }

                return _root;
            }
        }

        private void ClearApplicationNavigationBackStack()
        {
            if (Root == null)
            {
                return;
            }

            try
            {
                while (Root.BackStack.Any())
                {
                    Root.RemoveBackEntry();
                }
            }
            catch
            { }
        }
    }
}

And if you are really lazy today…

Here is the download link to the Visual Studio solution with Windows Phone application that uses this helper to terminate it self when a button is clicked…

Using Instapaper and other Mobilizer services in Offline Browser for Windows Phone

Mobile is the future!

Its a known fact that mobile usage of internet is growing.

More and more people are using primarily their phones and tablets to browse the web. Yet many websites are still not optimized for small screen devices.

My application Offline Browser for Windows Phone allows you to save whole web pages for later offline reading, but what to do if the website is not optimized for mobile devices?

Mobilize it!

This is where the concept of Mobilizer Services comes in.

Offline Browser supports multiple web services that can transform given web page into simpler version, where only content and images are kept and all other ‘noise’ is removed.

Here is the list of currently supported Mobilizers:

  1. Instapaper – currently the best option, creates clean output and preserves images
  2. Google Mobilizer – not so nice because it pages the content
  3. ReadItLater (now known as Pocket) – very nice but removes images

Each of those services are different and they give better or worse results when simplifying the webpage content – it often varies from website to website.

I prefer Instapaper since it gives cleanest output and shows images but you should try each of them to see which one is best for webpages you are opening.

Important thing to note here is that when Offline Browser uses these Mobilizer services to get the simplified content of web pages, all the images are saved to the phone and are available later when you view those pages when offline.

Another benefit of using Mobilizer service is that they reduce the bandwidth usage so if you have some tariff plan with limited number of MB this could help you keep the bandwidth usage as low as possible – not to mention that saving pages via Mobilizer is much faster!

So how do we enable this cool feature?

We just go to the Offline Browser Settings page and switch on this feature and choose which Mobilizer service we want to use.

Here is how this screen looks on the Windows Phone:

Once we enable the Mobilizer service all the pages we save to the phone storage are retrieved via the chosen Mobilizer and when you actually read the page you will see the mobilized version instead of the full webpage.

Here is how one of the web pages looks before using mobilizer:

As you can see webpage is not optimized for mobile devices and its not easy to read on the phone.

I deliberately used desktop browser user agent in the app Settings just to prove the point.

If we now switch to using Instapaper Mobilizer in the app Settings (and we still use the same desktop browser user agent) we will get completely different content:

As you see page is much easier to read, all the images are preserved.

Yet page is saved faster and less bandwidth is wasted.

So why not always use it?

Well i do use this all the time and only when Mobilizer services fail to retrieve content of some web page, then i switch it off and load original page content.

It all depends on your usage scenario and also on your data plan limits/internet connection speed etc.

Important thing is that you do have a choice and you can setup Offline Browser to work how its most convenient for you.

If you have any feedback regarding Mobilizers feature or you know of some good Mobilizer service that i should include in the app please send me a feedback via the Offline Browser Uservoice page and i will be glad to include it!

Using Offline Browser for Windows Phone as Instapaper client

 

 

Lets set some expectations here. We wont be adding new items to Instapaper.com reading list or removing items or anything similar.

We can use our desktop PC for that.

Here we will just explain how to use Offline Browser for Windows Phone to get all those links from Instapaper.com reading list via RSS feed and download them to the phone so we can read them whenever we want – even when we are offline.

So first we need to add the Instapaper unread items Rss feed into Offline Browser as a Links Feed.

Here is how you can do that:

1. Open the Offline Browser for Windows Phone and on the Browser page go to Instapaper.com and login to your account.

Once you are logged in, you will be redirected to this url: http://www.instapaper.com/u which is your unread items list.

2. Now we should find the RSS feed of your unread Instapaper items and use it as links source (Link Feed) of the Offline Browser app.

The RSS feed icon and link are at the bottom right corner of the http://Instapaper.com/u web page, take a look at the screenshot below:

3. Now long tap that link ‘This folder’s RSS’ and context menu of Offline Browser will appear:

4. Click on the “Add Link as Links Feed” item and RSS feed of your unread instapaper items will be added as Links Feed for the Offline Browser.

5. Now lets enable Links Feed synchronization in settings:

There we see the RSS feed from instapaper added to the app as Link Feed and we see that background downloading of the URLs from the feeds is enabled and done every 2 hours.

So even if our application is not running, a background task will retrieve the RSS feed and if there are new links they will all be added to the download queue.

When this happens you will get a toast notification and live tile of the Offline Browser will show number of new links retrieved from all feeds.

Here is how this looks on the Windows Phone start screen:

6. When we click on the Offline Browser icon and there are new items to download we are immediately taken to the download queue screen.

There you can simply click on the Sync button and all new links from download queue will be downloaded.

(app will also check if there are some newer items in the feed and retrieve them together with the items that are already in the download queue).

Once pages are downloaded we can go to the saved pages screen and open them in the browser screen:

Its important to say that once you go through this process and your instapaper RSS feed is added to the app, it becomes automatic and phone will download any links you add to your instapaper reading list.

So now that you know how you can use Offline Browser as your Instapaper client – go ahead, download it from marketplace and give it a try!