Set BaseActivity with a custom constructor to expose data from a child class

I have a BaseActivity that I use in my application to simplify Google Analytics.

In my basic operation, I override onStart() and onStop() to send some things to EasyTracker. I would like to set up my code so that it requires me to make a call to the superclass constructor with the name of the operation so that BaseActivity can send the necessary data.

I tried to create a constructor in BaseActivity , and it seemed to work, but I got an error message that my main activity (which extends BaseActivity ) hierarchy is incompatible.

What could I do for this?

+4
source share
1 answer

You cannot do this with constructors. The Android platform implements Android components ( Service , Activity , BroadcastReceiver , ContentProvider )), and you can not cope with it.

My suggestion is that you override onCreate() in your base activity and call subclasses of super.onCreate() from their overridden onCreate() method. In your base activity, you can get the subclass name by calling getClass().getName() .

+3
source

Source: https://habr.com/ru/post/1483652/


All Articles