which is better approach, put logout method to application or activity?
i have a logout button that appear in all my activity class except login activity,.
the logout button have the s开发者_C百科ame 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
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
精彩评论