Is possible to merge 2 activities in one

165 Views Asked by At

I have an android application working in mobile, this app has two types of activities ones that loads a list of items, and forms that open when you touch one item. Now I have to port the app to tablet and the layouts need to be fully restructured to fit big screens, so much that the java code has to be heavily changed so i thought to merge both activities in one as shown below enter image description here

Is that possible?

And if its what i need to use, fragments?

Can each activity still in its own class?(this is critical)

Can each activity have its own network operations and AsyncTasks?

2

There are 2 best solutions below

0
On

is not possible because only one activity working in single screen in android. i have one idea to put two fragment in single activity then use your own AsyncTasks network operation.

0
On

Yes as you said you can use fragments for your situation (Infact their main purpose is to support different screens without code duplication). So you'll have only 1 Activity class and 2 layouts for different devices and you just need to do some run time checks and perform actions according to them.

Here you can find tutorial :- https://developer.android.com/training/basics/fragments/index.html