Integrating Localytics - FragmentActivity

129 views Asked by At

Trying to integrate Localytics, step 6 assumes you extend 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());
}

In my class, MainActivity.java, we're extending a class that extends a class that extends a few more classes, finally ending with class that extend FragmentActivity. This is causing the following exception in MainActivity.java: cannot resolve symbol 'activity'

Edit

 Localytics.openSession();
 Localytics.upload();

 if (FragmentActivity.class.isAssignableFrom(this.class))
 {
     Localytics.setInAppMessageDisplayActivity(this);
 }
 Localytics.handleTestMode(this.getIntent());
1

There are 1 answers

1
Sam Dozor On BEST ANSWER

...where are you declaring the activity variable?

Replace activity with this in your code. Use MainActivity.this if you need to access a reference to your Activity from within an inner class.

Fix for the new issue:

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