整合Localytics - FragmentActivity

时间:2015-06-09 17:30:50

标签: java android android-fragments

尝试整合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());

1 个答案:

答案 0 :(得分:1)

...你在哪里声明activity变量?

在代码中将activity替换为this。如果您需要在内部班级中访问MainActivity.this的引用,请使用Activity

修复新问题:

if (FragmentActivity.class.isAssignableFrom(MainActivity.class))