How do I create common code for parts of Android activities?

后端 未结 2 1665
夕颜
夕颜 2021-02-06 06:23

In my application there are 14 activities. Out of that 9 activity contains custom title bar and tab pane. so here I need to write this common code at one place instead of redund

2条回答
  •  不思量自难忘°
    2021-02-06 07:02

    Hmm.. Common code doesn't always need to be in Activity class but just regular class. Than we could call those methods according to our needs referring to the common code class.

    Am I right with this example?

    Of course in case we need it like Activity, above proposal would work perfectly if we take care of Activity lifecycle and we don't forget to add it to manifest file.

    In general Activities should just create UI, handle events occurrences and delegate business logic and/or other actions to the other components in our App.

    Cheers

提交回复
热议问题