I'm triying to migrate my app from actionbarsherlock to Google's actionbarcompat, but ActionBarFragmentActivity does not exist. Do I have to use ActionBarActivity or there is another way?
Thanks in advance,
Diego.
Look here. This should help you out.
http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html
An Excerpt:
Extend Activity classes from ActionBarCompat:
ActionBarCompat contains one Activity class which all of your Activity classes should extend: ActionBarActivity.
This class itself extends from FragmentActivity so you can continue to use Fragments in your application. There is not a ActionBarCompat Fragment class that you need to extend, so you should continue using android.support.v4.Fragment as the base class for your Fragments.
Related
Is there a way I can extend both of these in a single activity? If yes, please share with me the source code.
From another SO answer:
To reduce the complexity and simplify the language, Android does not support multiple inheritance as it's based on Java programming language. Hence you can't extend both ActionBarActivity and YoutubeBaseActivity in a Single Activity.
The solution is pretty simple: use the YouTubePlayerFragment class. This does not pose any requirement on the Activity, leaving you with plenty of options for your theming.
Since the version 22.1.0, the class ActionBarActivity is deprecated. You should use AppCompatActivity.
Note : ActionBarActivity is deprecated, use AppCompatActivity.
Instead of having the Youtube player in the Activity (extending YoutubeBaseActivity), make your Activity extends from AppCompatActivity and use a YoutubePlayerFragment inside the AppCompatActivity. You will be able to use all the features of AppCompat with your Youtube video.
If you REALLY want to use BaseYoutubeActivity, you have to add an AppCompatDelegate in your own Activity extending the BaseYoutubeActivity and use it in every lifecycle method of your activity. Read the documentation of the delegate and read the original source code of AppCompatActivity to understand the delegate.
You cannot do that for now. you can use fragment instead of activity in your Activity that extends AppCompatActivity
Please refer to this answer. https://stackoverflow.com/a/30101931/4321808
I cannot decide what approach should I use in the next situtation.
One activity from my app need to have different functionality, here is the leak of multiple inheritence comes into play.
What I need to get ?
There are several parts that my activity has to have.
Navigation drawer. I am using MaterialDrawer library. It requires activity to implement on click callbacks (or use composition instead), but also it use activity as constructor argument,so I think it will be better to put this into separate class inherited from Activity or any base class provided by Android Framework . Thanks to library developer it doesn't require any stuff to be done in on create method ( setContentLayout for instance)
My activity(one of several) will have only Toolbar and FrameLayout for holding fragment . Or it is better to separate toolbar and single fragment ?
This in turn requires some stuff to be done in onCreate : setContentLayout with basic layout , add fragment to the container set activity actionbar .....
Maybe in future I will use another libraries that requires to add something in activity lifecycle methods.
All these points in order to follow Single Responsibility principle have to be separate classes inherited from some base Activity.
For example we will have something like this.
public class SingleFragmentActivity<T extends Fragment> extends AppCompatActivity {
}
public class SingleFragmentToolbarActivity<T extends Fragment> extends AppCompatActivity {
}
public class NavigationDrawerActivity extends AppCompatActivity {
}
....
As you can see each functionality is put into the separate class, but what if I need to have SingleFramgentActivity with NavigationDrawer ?
In this case I have to inherit one of these classes from another, for example
public class NavigationDrawer extends SingleFragmentActivity {
}
If to do so, I have no ability to use navigation drawer separately from SingleFragmentActivity.
What is the best practice to follow in this case, how to build class hierarchy to make it flexible and use Open-Close principle, to make changes in application without any pain. (Use strategy, decorator ..... ?)
I would be grateful everyone for help.
In my project i am using fragments and activities. in one of activity i used youtube video api, now i want to call fragment from that activity but they are not allowing without fragmentactivity and i extended youtubebaseactivity in that activity.so please help me
extend yourclass with ActionBarActivity and you can Access both functionality.
Thats it...
I have my application code base with multiple activities in it. I have a BaseActivity class which extends Activity class and is the parent class for all Activities in my application. BaseActivity takes care of the state my application goes in background and comes back to foreground.
Now I have written few more Activities which are using fragments so these new Activities are extending FragmentActivity. But my application design requires that all activities should extend BaseActivity class.
Solution in my mind:
BaseActivity extend FragmentActivity instead of Activity class.
New activities(with fragments) extend BaseActivity instead of directly extending FragmentActivity.
With this solution I am afraid of any side effect in my existing activities which were extending Activity class (through BaseActivity). Now these activities will extend FragmentActivity (although they are not having fragments inside).
Is it okay if I extend FragmentActivity even though I dont have any fragment inside. Will it behave same as Activity?
as FragmentActivity extends Activity so looks it's fine.jsut you need to add compitiblilty library if want to give the support for old versions
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
Even I did same and found no side effect yet
Here is the deal : I need to extends two different classes in Android.
An example:
In MainActivity.class I need to extends first TabActivity to use the tabs and getTabHost(); and in the same class I need to extends for example ListActivity or something else...How can I do that? Maybe my question is a little stupid but...
Thanks anyway!
You can extends either TabActivity or ListActivity in your main Activity.You can't extends two all together because java does not support multiple inheritence.After extending any one create the reference of another to use in your activity.
Your MainActivity doesn't need to extend TabActivity and ListActivity at the same time.
Only MainActivity needs to extend TabActivity and you can use a different Activity which extends ListActivity as the content of one or more of the tabs.
Here is the really good official documentation which has an example of what I'm talking about : http://developer.android.com/resources/tutorials/views/hello-tabwidget.html