I was following Android tutorials from mybringback and he was using his created class and it was, by default, extended to use Activity and since that video was made a while ago, I'm guessing that ActionBarActivity wasn't available then.
However in the tutorial he uses super.onPause in his media file video, which is not available in the override methods for ActionBarActivity, so I was wondering, if there was another way for me to do the same thing, if onPause would be called something else in ActionBarActivity, or if I should just change ActionBarActivity to Activity instead.
Thanks!
In eclipse if you want to use Source->Override/Implement Methods, to generate the onPause method, you need to look under the FragmentActivity expansion, since ActionBarActivity is a subclass of FragmentActivity
ActionBarActivity subclasses FragmentActivity
FragmentActivity subclasses Activity
Activity contains method onPause()
Therefore, yes! There is an onPause() method in ActionBarActivity
You should really learn to use documentation and not rely on override implement methods feature in Eclipse https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
Related
I have an android wear app that contains a FragmentActivity:
public class MyFragmentActivity extends FragmentActivity
With 2 Fragments:
public class MyFirstFragment extends Fragment
and
public class MySecondFragment extends Fragment
I want to enable the ambient mode (always on) in this fragment activity. However, according to the documentation, the ambient mode is only available if i extend WearableActivity.
Is there a way to have both properties of the FragmentActivity & WearableActivity together in one?
or
Is there another way to enable the ambient mode in the FragmentActivity?
You should implement AmbientModeSupport.AmbientCallbackProvider instead of WearableActivity, then you can extend FragmentActivity instead.
It is the new preferred method and it still gives you all the goodies you got with WearableActivity but also lets you use Activity (or any sub classes... FragementActivity, etc.).
Official docs call out the details (and example code).
Update: Use AmbientModeSupport now instead of AmbientMode. Google recently changed the name, so the old version is deprecated.
Answer to both questions is no, sorry.
Ambient mode is enabled by calling WearableActivity.setUseAmbient(), which obviously is not available if you're not extending WearableActivity. And since Java doesn't support multiple inheritance, you can't subclass both WearableActivity and FragmentActivity at the same time - it's one or the other.
Do you really need to be using Fragments on a watch activity? If you really want to support ambient mode, you probably need to look at moving your UI out of fragments.
If you want to use Fragments on Android Wear and support Ambient mode, you need to use the AmbientModeSupport class.
Make your activity extend FragmentActivity and implement AmbientModeSupport.AmbientCallbackProvider and you're all set!
Details and examples are here: https://developer.android.com/training/wearables/apps/always-on#ambient-mode-class
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 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
I'm trying to use EasyTracker in my project. But one of the Activities extends TabActivity.
To use EasyTracker all activities have to extend TrackedActivity.
I guess it's not possible to extend it with my TabActivity subclass without modifying Android's or EasyTracker's source.
I'm wondering if it's possible to mix "normal" Tracking (which I would use for this Activity) and the inheritance Tracking of EasyTracker. But seems to be at least not advisable. From EasyTracker doc:
Note that all of your Activities must extend TrackedActivity (or an
equivalent Activity, like TrackedListActivity instead of ListActivity) for
this Class to properly track application usage and time.
So what do I do?
The solution is pretty much simple, but I was to lazy to find it yesterday.
Download source of EasyTracker
Copy TrackedActivity and rename it in something like TrackedTabActivity
Make it extend TabActivity instead of Activity
Include this file in the project
Make the subclass of TabActivity extend TrackedTabActivity instead
Same principle for other activity subclasses like PreferenceActivity, etc.
I have googled but I have not found an equivalent flowchart showing the life cycle of PreferenceActivities in android. Does such a flowchart exist? The one showing basic activity lifecycle was a big help getting to understand how activities work.
The PreferenceActivity class extends the Activity class¹, hence the same lifecycle applies.
A PreferenceActivity just does some things for you in the relevant lifecycle methods, see the source. Since you have to call the relevant superclass methods anyway, there isn't any major difference (e.g. you have to call super.onPause() when you override onPause()).
¹ it extends a ListActivity, which then extends the Activity class