One APK to rule them all

I wrote this a while back on a forum post and never posted it here. I figured it was good information and could help other Android nerds as well.

Having one apk to rule them all is a tricky thing to manage. I just recently launched with normal, large, and xlarge layouts along with landscape for large and xlarge. It is not easy, it takes a ton of regression testing, but is totally worth it.

There are some people that are developing separate apps for tablet. I wouldn’t recommend it, personally. Maybe if you pull out all business logic and throw it in a library it may be easier but there would still be a ton of redundant work. Abstract out the work of building out the views, and that will allow you to manage each resolution re-using the same techniques.

One tip is to have a very easily accessible flag that allows you to differentiate which device size you’re running on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//check to see if we have a tablet, large or phone, and then set the global flag
int screenLayout = getResources().getConfiguration().screenLayout;
model.isTablet = 
   ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
 
//if isTablet is false, check to see if we have a Large device, else
we have a phone
if(model.isTablet == false){
   model.isLarge = 
       ((screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
   if(model.isLarge){
      model.deviceSize = "Large";
   }else{
      model.deviceSize = "Phone";
   }
}else{
   model.deviceSize = "Tablet";
   model.isLarge = false;
}
 
//throw in a isLandscape if that matters as well. 
public boolean isLandscape(Context context) {
   int orientation = context.getResources().getConfiguration().orientation;
   return (orientation == Configuration.ORIENTATION_LANDSCAPE);
}

by using these flags on simple singleton model, you can easily build out the appropriate view for any scenario….except for small. just add a new flag for that 😉

Leave a Comment

Your email address will not be published. Required fields are marked *

  Wordpress Theme Protected By Wp Spam Blocker