尝试整合Localytics,第6步假设您扩展FragmentActivity
:
In onResume, open a session, start an upload, and register the activity for marketing.
public void onResume()
{
super.onResume();
Localytics.openSession();
Localytics.upload();
if (activity instanceof FragmentActivity)
{
Localytics.setInAppMessageDisplayActivity((FragmentActivity) activity);
}
Localytics.handleTestMode(activity.getIntent());
}
在我的班级MainActivity.java
中,我们扩展了一个类,该类扩展了一个扩展了更多类的类,最后以扩展FragmentActivity
的类结束。这导致MainActivity.java
中出现以下异常:无法解析符号'activity'
修改
Localytics.openSession();
Localytics.upload();
if (FragmentActivity.class.isAssignableFrom(this.class))
{
Localytics.setInAppMessageDisplayActivity(this);
}
Localytics.handleTestMode(this.getIntent());
答案 0 :(得分:1)
...你在哪里声明activity
变量?
在代码中将activity
替换为this
。如果您需要在内部班级中访问MainActivity.this
的引用,请使用Activity
。
修复新问题:
if (FragmentActivity.class.isAssignableFrom(MainActivity.class))