1

i have a logout button that appear in all my activity class except login activity,.

the logout button have the same logic for all activity class, it simply tell the server the user is logged out, clear all of the shared preferences data, and bring the login activity to foreground

create an application subclass that have logout method, or an activity subclass that have logout method and all of my activity extends from this class..

which is better approach to achieve this? and what is cons and pros, if have any? thanks

Hendra
  • 43
  • 2
  • 10

1 Answers1

0

Neither. Since your layout is reused across activities you should probably include/merge your logout view into all the others: http://developer.android.com/resources/articles/layout-tricks-merge.html

For a more detailed discussion look here: Inheritance vs. Aggregation

Community
  • 1
  • 1
mibollma
  • 14,959
  • 6
  • 52
  • 69
  • In a good application the logic code should be detached from the display code: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller – mibollma Jun 22 '11 at 18:57
  • from the article, it suggest me to create new linearlayout sub class, and then i implement the logout button logic in this class, am i corect? so what if there is another button that do different logic?say, there is an refresh button(again it appear in all my activity except login activity), each activity have different implementation, if its a list, then it will clear the list, pull some fresh data from server, and add it to the list.. and in other activity, it clear some detail from some textview(not a list, just linearlayout that have some textview), and display the detail.. thx – Hendra Jun 22 '11 at 19:01
  • i dont understand, so where i put the method in this case?? sorry to trouble you, i'm new in IT world – Hendra Jun 22 '11 at 19:07
  • One approach would be... create a custom view(group) called LogoutView... include/merge that one in all your activities. It contains your logout button and maybe more stuff. When the Button is clicked you call a function like ServerApi.logout(); to log out from the server. The logic is implemented in the class ServerApi. – mibollma Jun 22 '11 at 19:16
  • and if there is refresh button? see my comment above for detail.. how will i know it comes from one activity that requires to clear the list or some textview in linearlayout? – Hendra Jun 22 '11 at 19:29