Search code examples
androidandroid-layouttablet

How to write a same android application for both phone and tablet devices?


I have two activities A and B in android application.On phone devices A launches into B.But I want to show both activities as fragments in the same activity on large tablets.

How to achieve this?Just writing different layouts won't work as logic will also change.So should I release two 'apks' for both phone and tablets?If not then how to write logic for both in the same application?


Solution

  • First of all, you need to modify your design to use a single activity and two fragments. The two fragments are the "master" and "detail" which can be reused in both the tablet and phone versions. So for example, you can make master.xml and detail.xml layouts. Then you create different activity layouts for different devices sizes and/or orientations. For example, you can have a default main.xml in the layout folder and a main.xml for tablets in the layout-large-land folder.

    You can do this all in a single APK. I suggest that you google "master detail for android". This is the name for what you are trying to do.