在我的父类中:
// 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,但它不起作用。