在我的父类中:
// ParentActivity.java
@Override
protected void onResume() {
if (this instanceof ParentActivity) connectToGoogleAnalytic("parent");
// do something else
super.onResume();
}在子类中:
// ChildActivity.java extent ParentActivity
@Override
public void onResume() {
if (this instanceof ChildActivity) connectToGoogleAnalytic("child");
super.onResume();
}这种情况下,如果活动是ChildActivity,那么当调用onResume时,它也会调用ParentActivity's onResume,而不是调用ChildActivity's onResume并弄乱分析的数据。我尝试使用instanceof检查this是否等于ParentActivity,但它不起作用。
发布于 2013-06-10 22:47:22
如果ChildActivity扩展了ParentActivity,那么ChildActivity的实例既是ChildActivity又是ParentActivity。
由于您调用的是super.onResume,因此您可以删除
if (this instanceof ChildActivity) connectToGoogleAnalytic();来自ChildActivity.onResume
https://stackoverflow.com/questions/17026532
复制相似问题