Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending an additional class within a main activity that already extends ActionBarActivity?

I am attempting to add the same action bar compatibility found in the Google "ActionBarCompat" sample code to one of my projects.

My problem is that I already extend MapActivity in my main class, but the main class of ActionBarCompat seems to require that you extend ActionBarActivity.

Here's my Java 101 question: I know enough about Java to know that I can't have multiple inheritance, but not enough to know the ideal way to handle this situation. My solution was to extend ActionBarActivity in my main class, but then make ActionBarActivity extend MapActivity. Is this the correct way to do this? If so, wouldn't I have to make a duplicate ActionBarActivity if I want it to extend other things?

Thanks for your consideration of this question!

like image 424
gsysko Avatar asked Nov 28 '25 22:11

gsysko


2 Answers

Yes, that's a totally valid way of doing this. If you want an ActionBarActivity class that doesn't extend the MapActivity, you'll have to create another class. I don't think this will lead to a lot of code-duplication (which I'm guessing is what you're afraid of). Shame on the android developers though for making you need to code your own ActionBarHelper class.

like image 167
Kurtis Nusbaum Avatar answered Dec 01 '25 12:12

Kurtis Nusbaum


Look at the example you provided - ActionBarActivity is only having an ActionBarHelper field and calling methods on it. Try doin the same in you MapActivity.

like image 44
Peter Knego Avatar answered Dec 01 '25 11:12

Peter Knego



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!