Using a custom LayoutInflater.Factory with AppCompatDelegate - android

My custom factory isn't getting called in ActionbarActivity anymore with AppCompatDelegate as of v22.1.1.
I see in the docs that in this case you shouldn't call AppCompatDelegate.installFactory() (and a custom activity seems to support this) but if this is the case then I can't use AppCompatActivity/AppCompatDialog (and possibly the new builder?) or anything that inherits from those classes. So basically I need to reimplement the non-material versions (ie actionbar parts) of AppCompatActivity.
Is this actually the case or am I doing something wrong?

Using android.support.v4.view.LayoutInflaterCompat solves the problem.

Related

How to extend ActionBarActivity and YoutubeBaseActivity?

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

AppCompat v7: Should I use Framework FragmentManager or SupportFragmentManager?

I am making an app which should have minSdk = 15 and targetSdk = 21, therefore I want to use the features provided by the appcompat-v7 library.
I always wondered if I should use getFragmentManager or getSupportFragmentManager when using the supportlibrary-v7.
I am encountering a small problem now: when using getFragmentManager (and therefore using the framework fragments and fragmenttransaction) I wasnt able to pop the backstack by simply pressing the backbutton - I had to do a backStackCount > 0 check and manually popBackStack, otherwise my activity was simply finished. This problem was solved when I switched my small app to use the v4 classes (getSupportFragmentManager etc.). Which is fine I guess, but I would like to have a guideline/bestpractice to know which way to go and why
So, my Activity is inheriting from ActionBarActivity (according to AppCompat-Blog-Entry) and I am using the new toolbar, should I use only v4-Fragments(-Manager, -Transactions)?
I havent found any best practices or guidlines for that. And I am unsure about what to consider when deciding between these two :-/
If you are inheriting your activities from ActionBarActivity you should always use getSupportFragmentManager(). It automatically forwards your calls to getFragmentManager() if the phone supports it (runs Honeycomb or later), otherwise it uses its compatibility implementation.

Is there an onPause in ActionBarActivity?

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

Difference between Activity and FragmentActivity

I was working on fragments and came across two things Activity and FragmentActivity which are used several times. I want to know that is there any difference between these two, because when I changed Activity with FragmentActivity, it had no effect on the app.
A FragmentActivity is a subclass of Activity that was built for the Android Support Package.
The FragmentActivity class adds a couple new methods to ensure compatibility with older versions of Android, but other than that, there really isn't much of a difference between the two. Just make sure you change all calls to getLoaderManager() and getFragmentManager() to getSupportLoaderManager() and getSupportFragmentManager() respectively.
FragmentActivity is part of the support library, while Activity is the framework's default class. They are functionally equivalent.
You should always use FragmentActivity and android.support.v4.app.Fragment instead of the platform default Activity and android.app.Fragment classes. Using the platform defaults mean that you are relying on whatever implementation of fragments is used in the device you are running on. These are often multiple years old, and contain bugs that have since been fixed in the support library.

EasyTracker (GoogleAnalytics) for Android in TabActivity and others

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.

Categories

Resources