The right way to launch other apps
After a a recent experience with some major apps on the Android platform I was inspired to write another post. The issue we’re going to look at today is launching other activities from your app, and how there are some useful flags we can specify in our intents to give a more polished experience for our users.
As an app developer there are many scenarios where I want to launch other apps on the device. This is almost always accomplished using Androids wonderful intent system, but there are scenarios where you can improve the experience for your users. Lets look at an example of this flow.
I have Facebook installed on my phone and try to access the Instagram application from the sidebar. Since I don’t have the app installed Facebook opens the Play Store and directs me to the download page for Instagram.
This is all sounding great so far right? Now for whatever reason I get distracted and hit the home button or take a call etc. Lets take a look at what happens next time I hit the Facebook icon on my home screen:
Boom just like that I’m right back where I left off, but I’m in the Play Store. Wait what?! That’s likely the reaction of many of your users, especially if they have been gone for a long time. Even though they clicked on the Facebook icon they are in the Play Store looking at the Instagram listing. Now Android is doing its job here, exactly what we asked it to do but in this case I don’t think its the best experience for our users. It would be better for them to always end up in our app when they launch it from the home screen.
Luckily there’s a really easy fix. Whenz creating our intent we just need to set a flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET so that android knows this is a break in the flow of our app. We are telling the system the next time a user resets ( or reopens ) our app please clear this activity off the stack.
Quick example of the code to set a flag on our intent:
Intent testIntent = new Intent( Intent.ACTION_VIEW, Uri.parse("market://details?id=packagename")); testIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(testIntent);
This is really easy to accomplish and you should consider updating your apps if they fall into this trap! Let us know what you think in the comments.