Umair
Umair

Reputation: 6426

How to manage code for different design to support all devices

I have an app and that's already been made for large devices i.e 10 inch tablets and kiosk. I made the same design for the mobile phones but that was not looking good ,so I thought to move the mobile device to material design and the rest of the devices (tablets & kiosk) would remain same.

I know how can I make different layouts for the different devices i.e normal , large and x-large but I am worried about the code. So basically followings are my confusions....

I have also searched through stackOverflow and only came up with these two links that were close to my question but rest of the links are about different layouts not the code:

  1. Android app for phone and tablet: 1 or 2 apps?
  2. Creating different layout for android phone and tablet

I hope I am quiet clear in my question please answer my these question with some authentic reasons and links.

Upvotes: 1

Views: 336

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83527

The Support Libraries are designed to minimize the amount of work you need to do to detect differences in the Android version where your app runs. For example, RecyclerView is available in the Support Library. Between this and layout-xxx folders, you can usually build a single APK for all API levels and device form factors.

Upvotes: 1

Mike
Mike

Reputation: 5572

Multiple apks for a single app is supported in Google Play. However, unless your app is very large (greater than 100MB) they recommend you release one apk for all devices.

So you need to inspect the screen size at run-time. You can do this by category, by device independent pixels, or even in inches. Then, as you said, you would load the appropriate layouts and fragments accordingly.

Even if you were to use different apks, you would likely do it in a similar fashion because you probably want to share SOME code.

In Gradle you would make productFlavors for each apk, along with a variable to define the build like this:

productFlavors {
    bigtablet {
        buildConfigField "String", "deviceType", "\"bigtable\""
    }
    smalltablet {
        buildConfigField "String", "deviceType", "\"smalltable\""
    }
}

Then at runtime you would use the BuildConfig.deviceType to drive the exact same logic as the screen size did in the one apk method. With this method Gradle will strip out all the unused code from each apk.

The last option would be create completely different projects for each apk. Pushing all the shared code into libraries.

You can always put it all in one apk for now and switch to multiple productFlavors if the apk grows too large. Since the logic is similar it wouldn't be too hard to swicth. Hope this helps.

Upvotes: 3

Related Questions