0

I am developing a local music player application in which I am having a common view (player) that has four button (play, pause, previous and next).
I need to use that view in all activities ie. song list, album list, artist list. In sort user should be able to operate player from all screens.
One way is to create a common activity and extends that activity in all actvity and inflate player layout but in this case i have to implement click events in all activities.
what is the best way to implement this.

many thanks.

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
user465125
  • 109
  • 2
  • 9
  • 1
    You can use a single xml for that footer and include that in all xmls, but in that, too, you would have to add onClick event in all activities. – MysticMagicϡ Nov 15 '14 at 16:08
  • implement click listeners in base activity only, why in all? – pskink Nov 15 '14 at 16:10
  • Instead of using different activities just use different fragments. And the footer will stay in your parent activity. – Simas Nov 15 '14 at 16:12
  • What @MysticMagic said, then create a special purpose Activity that has the code to handle the buttons in the footer and let all other Activities extend that. Then you only need to write the logic once. It would probably be best with a single Activity with different fragments as mentioned by user3249477, but if that is all new to you, then the suggested solution should do fine. – cYrixmorten Nov 15 '14 at 17:23

2 Answers2

0

The best approach to this is by using Fragments. Create a fragment which connects to the service and provides an UI to control it, then add this fragment to all the activities where you need it or add the activity to a parent activity and extend it by using inheritance in all the child activities.

0

Make a footer layout file and then use include in all layout file you want to display that footer,

 <include layout="@layout/footer" />

use weightSum to manage height of footer in all screen

OR

you can also try switching activities without animation.

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142