Working With WebViews

Share if the site was helpful

Working With WebViews

It’s a different kind of www, but working with WebViews can completely change your development potential.  If you’re an experienced developer but have very little mobile app experience, WebViews might be exactly what you’re looking for.

Taking a Step Back:

Before diving into this newly hyped up feature, let’s take a second to actually explain what a webview is. To your app it’s not much more than a black box (the term for something that performs logic you’re unaware of).  A lot of stuff happens in a webview but for the most part your app can ignore it.  It’s just another View the same way Buttons or TextViews are.

But webviews are so much more to your user.  They’re a view that displays a web browser and allows the user to navigate to new web pages.  Access to the entire internet with almost zero development!  There’s a little set up logic but that’s all you need.

So why would you want this?  Well usually the answer is work efficiency.  If you’re building an app and a website, it’s not ideal to do twice the work.  It is ideal to build good experiences for your userbase though, and that’s why not everything is a webview.  Native app experiences will be a lot smoother and responsive, whereas with a webview you’ll have to wait for everything to load on the page.  That being said there are uses for either scenario

Setting It Up:

Setting up a WebView in your app is extremely simple.  As with most views there are two parts to it, defining the view in your xml activity and then syncing it up with an actual WebView object in your java/kotlin code.  To declare the view in your xml you’ll create it the same way as other views:

         <WebView

               android:id="@+id/webview"

               android:layout_width="match_parent"

               android:layout_height="match_parent" />

 

And that’s it!  Now to sync it up with your logic you’ll need to create an instance of the WebView class and anchor it to the xml view.  Using a popular Android library like Butterknife it looks something like this:

        @BindView(R.id.webview)

        WebView webView;

Then you’ll need to implement WebViewClientListener and add this associated method:

        webView.setWebViewClientListener(this);

And finally we can override these three methods:

        @Override

        public void onPageStarted(final WebView view, final String url, final Bitmap favicon) {

            //Do something when a page starts loading

        }

        @Override

        public void onPageFinished(final WebView view, final String url) {

            //Do something when a page finishes loading

        }

        @Override

        public void onPageCommitVisible(final WebView view, final String url) {

            //Do something when a page is visible

        }

What we’ve done at this point is added a WebView to our screen.  We’ve also added methods to respond whenever a page changes on the WebView.  What this means is our app is now able to natively respond to new URLs a user loads in the WebView.  What you do at this point is up to you and your creative limits!

Interacting With WebViews:

While we said earlier that a WebView is a black box, there are a couple different ways you can interact with them.  Like we saw above you can see the URLs that are loaded and use those in your apps. But you can also get much more intertwined by either listening for JavaScript methods or calling JavaScript methods on the WebView.  To do these you need to know what’s going on with the website users are looking at, but it can create some really cool experiences.

You can also track what cookies are on the site.  There are a couple useful interactions to be aware of, and we’ll cover them all in another post soon.  In the meantime you should try adding a WebView to your apps and let us know what you think in the comments below.

 

 

 

Google Maps Crashes Around The World

Share if the site was helpful

Google Maps Crashes Around The World

A few days ago, panic struck apps around the world.  In a nightmarish turn for any developer, every app using Google Maps crashed.  Not just once, but every time it attempted to load Google Maps.  The result being if you launched the Maps SDK on launch, 0% of users could open your app.  Not. Good.

Fallout and Recovery:

A little while after the crisis bubbled up Google released a hotfix.  But users who had experienced the crash were doomed to continue experiencing it.  That is until they either cleared their cache or uninstalled the app.  Developers were forced to release their own updates with a suggested bit of solution code.  Unfortunately, even with this fix only users who updated their app could be free of the bug.

Apps are still climbing back from this fall, but the experience brings up a couple key components of app development that we’ve talked about here at RootJunky before.  These include error handling, dealing with live production changes, and utilizing crash reporting tools like Firebase.

Ignorance Is NOT Bliss:

When it comes to app crashes, it is never a good thing to turn a blind eye.  Something like the above may have occurred that isn’t necessarily your app’s fault, but you still need to know when to react.  Google has now released a new version of Google Play Services that fixes the issue, but this took days and every hour counts when it comes to things like app ratings and revenue.

Being aware of the crash at hour 1 gives your team time to evaluate the issue and begin investigating possible solutions.  And let’s not forget about the pesky fact that ALL developers introduce bugs sometimes.  Seeing your new app version start to crash more often than others can be crucial if you need to address something before it is released to all users.  Long story short: without crash reporting from a tool like Firebase you’re up a creek without a paddle.

Error Handling:

When our apps do experience issues, it’s also important they are able to be handled correctly.  Sometimes crashing an app can be the best outcome of a situation, but what about scenarios where the issue isn’t that serious?  For example what if our app couldn’t load a user’s info.  Would it be better to display a message to the user telling them to try again later?  Or would it be better to inexplicably crash the app on them?

This is where error handling comes in.  Using things such as try-catch statements can allow us to handle issues in the app’s code without destroying the user’s experience.  In the “try” section of your code you attempt to do something.  And then in the “catch” section you handle any error that may have taken place.  If you’ve ever built an app you’ve undoubtedly used try-catch, but are you using it in all the right places?

Remote Config to the Rescue?

One other option that we’ve discussed before is Remote Config.  Using this tool you have the ability to change settings of your app remotely without having to release an update.  Let’s relate this to the Maps SDK crash.  We could set something up in our code to check if a Remote Config value shouldInitializeMaps is true.  If so then we load a map, otherwise don’t even present this option to a user.  By setting things up this way we now have the option to shut off Google Maps if it becomes problematic.

Bill Gates captured it quite well when he said “It’s fine to celebrate success but it is more important to heed the lessons of failure”.  When things go wrong we should view them as a learning opportunity for how to make our apps even stronger down the road.

 

Android 11 Has Made Its Debut

Share if the site was helpful

Android 11 Has Made Its Debut

 

Gone are the days of Android versions with dessert themed names.  But by no means does that mean the end of Android!  Google is still keeping to their schedule of a new version every year, and 2020 marks the year of Android 11.  It won’t have a fun name, but this version may contain some long-awaited features for the world’s most popular operating system.

Android 11 Today:

Google has launched their first developer preview of Android 11.  What does this mean?  It doesn’t actually mean that you have to be a developer to view it, just that you can’t download the new version in the traditional sense.  Instead you can utilize the system images for Google’s Pixel devices to flash the software onto your phone.  For more detail on that check out this post.

Let’s take a look at what 11 is going to bring to the table. Google’s VP of Engineering Dave Burke spoke about it saying “With Android 11 we’re keeping our focus on helping users take advantage of the latest innovations, while continuing to keep privacy and security a top priority.”  The version is focused on helping manage sensitive files in an era where privacy feels non-existent.  For permissions that typically require user approval, Google is expanding their “Just this once” option to features such as accessing your contacts or camera.  Something introduced last year for locations that has proven to be useful.

New Developer APIs:

Android 11 actually seems to be bringing a lot of new features to the table right out of the box.  New APIs available to developers include 5G bandwith estimates, conversation sections in the notification shade, and fun chat bubbles that behave similarly to the Facebook chat we’ve all more than likely used in the past.

There are also improvements on existing features such as dark mode and NFC.  This will hopefully help with the issue of jumping back and forth between apps that have/have not implemented dark mode (it’s tough on your pupils!).  And an expansion on Project Mainline will allow Google to update key components of the OS via the Google Play Store instead of waiting for device manufacturers to release full rollouts.  More updates = better user experiences.

When we’ll learn more:

Unfortunately Google I/O has been cancelled this year as an in-person event, but the online portion will still be available.  It’s always a great event to see the new pieces of tech that Google has been working on both. We’re sure to learn more about Android 11 in May, so stay tuned to hear updates then.

What are your thoughts on what the latest Android version has to offer? It’s still being refined and will likely be officially available in Q3 of 2020.  While it’s just “Android 11”, we’d technically be on R.  So if you want to brainstorm what a good dessert would be for this version’s name let us know in the comments below!

en English
X