Same activity but different layouts?

Viewed 44

I'm kind of new to android java so I started to create a Music Player app just to learn and practice. The main thing was to control the same MediaPlayer from 2 different activities (In MainActivity there's a listview with the music files and PlayerActivity has the MediaPlayer). I tried to use public voids like:

PlayerActivity pa = new PlayerActivity();

//button onClick
pa.songPlay();

and it kind of worked at first but then a lot of errors occurred when using contexts and MediaPlayer.create(), so I started to look for another way to do this but found none so far. Is there a way to make 2 different layouts with a shared element, and with the same class?

For a better explanation:

MainActivity: MainActivity

PlayerActivity: PlayerActivity

And fuse them like: Fused layout

1 Answers

Okay so I'm answering my own question because I didn't know that FrameLayouts exist, but since I found them I can put two different layouts into the same space and just set the visibility to VISIBLE or GONE whenever I want to switch between them

Related