lory105
lory105

Reputation: 6302

Android common super class for Activity and FragmentActivity

I want to create a generic super class called Vista that extends android Activity, and then create all my activities extending my class Vista (thus to inherit all my common methods in all my activities). But in the project I have some FragmentActivity classes and I can't extend these from the class Vista.

Any solution? Can i change my FragmentActivity in a simile Activity and use android.app.fragment with TabHost inside, instead of android.support.v4.fragment because I am develop for android 4+ ?

enter image description here

Upvotes: 2

Views: 2324

Answers (2)

James Holderness
James Holderness

Reputation: 23001

You need to make the Vista class a standalone helper class. Then create an ActivityVista class that extends Activity and includes an instance of the Vista helper class as a private member. And also create a FragmentActivityVista class that extends FragmentActivity and includes an instance of the Vista helper class.

The ActivityVista and FragmentActivityVista classes will have to have a bunch of forwarding functions that call through to the Vista helper class, but they at least won't have to duplicate the full functionality.

Upvotes: 3

Yakiv Mospan
Yakiv Mospan

Reputation: 8224

You have 2 ways :

  1. Add VistaFragmentActivity and extend it for Fragments
  2. Make yout Vista to extend FragmentActivity

Best wishes.

Upvotes: 1

Related Questions