Java – use a custom constructor to set baseactivity to provide data from subclasses

I used baseactivity in my app to help simplify Google Analytics

In my basic activity, I override onstart() and onstop() to send something to easytracker. I want to set up my code so that it requires me to call the superclass constructor with the name of the activity so that baseactivity can send the correct data

I tried to set the constructor in baseactivity, which seemed to work, but the error I got was that my main activity (extended baseactivity) hierarchy was inconsistent

What can I do to achieve this goal?

resolvent:

You can't use constructors to do this. The Android framework instantiates the Android components (service, activity, broadcastreceiver, ContentProvider) themselves. You can't solve this problem

My suggestion is that you override oncreate() in your basic activity and let your subclasses call super. Oncreate(). In your basic activity, you can get the subclass name by calling getclass(). Getname()

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>