Java Question Extending Activity class

warwound

Expert
Licensed User
Longtime User
Why do you need to extend Activity?

It will be simpler to just expose onStartSession and onStopSession and let the developer call them from Activity_Resume and Activity_Pause.

There's no real reason for this - i was really just looking for a reason to test out the #Extends attribute.

If i get it working i have a client that would like to have both Google and Flurry analytics used in his app and extending the Activity as i have tried would make it really simple!

Any idea why my AnalyticsActivity fails to compile?

Martin.
 

warwound

Expert
Licensed User
Longtime User
Silly me!

Not only did i add the #Extends attribute to the Project attributes and not the Activity attributes, i also used the wrong classname!
It compiles fine now.
 

warwound

Expert
Licensed User
Longtime User
Actually I don't think that your solution is simpler. It requires editing resource files. You shouldn't assume that BA.applicationContext is ready in your code.

Lol yeah my static constructor fails as you guessed.
 

vpires

Member
Licensed User
Longtime User
B4X:
AddApplicationText(<meta-data android:name="flurryEnabled" android:value="true" />)
AddApplicationText(<meta-data android:name="flurrySdkKey" android:value="myKey" />)
in the manifest, and for example in the java class
B4X:
@Override
    public void onCreate(android.os.Bundle savedInstanceState)  {
        Log.d("B4A","OnCreate");
        super.onCreate(savedInstanceState);
       
        try {
            ApplicationInfo ai = this.getPackageManager().getApplicationInfo(this.getPackageName(),PackageManager.GET_META_DATA);
            FLURRY_ANALYTICS_ENABLED = ai.metaData.get("flurryEnabled").equals("true");
            FLURRY_API_KEY = (String) ai.metaData.get("flurrySdkKey");
            }
        catch (PackageManager.NameNotFoundException ne) {
            FLURRY_ANALYTICS_ENABLED=false;
        }   
    }
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…