Closed erichkleung closed 8 years ago
When the app engages an Apptentive event, given the targeting conditions are met, an Apptentive internal Activity will be launched to display things like rating prompt, message center, etc ... This internal activity is also known as ViewActivity
, which we ask you to declare in AndroidManifest. The Activity
parameter used in Apptentive.engage
is THE activity that will call startActivity()
to launch our ViewActivity
, and being pushed into activity stack. Once user back from Apptentive activity, this launching activity will be brought to foreground.
Context by itself cannot be used to launch another activity. We could do instance of
check at runtime to make sure context
being passed into engage
is indeed an Activity
, and launch nothing if it's not. But making the first argument a type of Activity
makes engage
method strongly typed.
Context can be used to launch another Activity so long as the Intent has FLAG_ACTIVITY_NEW_TASK, iirc.
technically you are absolutely right. But as a SDK that launches activity, Apptentive tries not to use this flag, which would result in a new task being created for Apptentive activity. Majority of our customer prefer to have Apptentive activity being created in their existing task back stack.
Makes sense. Also makes sense for people to be concerned about holding onto an Activity reference. Looks like you all are doing things right. I've had a PR hanging since October because a third party SDK attempted to hold onto a single Activity reference for the duration of the app.
Is there a way to track events with the engage method without using Activity as context?
For example we need to track an event as soon as the application starts, at this point only the application context is available (no Activity) and the engage method cannot be used.
Currently Apptentive sdk doesn't have a public method that will allow tracking event with a non-activity context. The primary reason for such a design decision is outlined in one of the earlier reply. But we also hear and understand your specific requirement, and we are considering making changes in our sdk to accommodate in future releases.
As a short-term work-around, could you store the event in persistent storage, such as shared preference during app launch, and track it in the onCreate() of the your first activity? Of coz, you need to remove the key from the shared preference once it's tracked, a.k.a "engaged".
Thanks for your suggestion, but we prefer to wait for a public method. Is it possible to get the method with the next release?
We will be implementing this as part of our next major release. Stay tuned!
This is implemented in 3.0.0. Enjoy!
Not entirely sure where to post questions, decided this might be a good place.
Why does
Apptentive.engage
take inActivity
as an argument vs taking inContext
? Going down the chain, the Activity/Context continually gets passed around, and the only places it's used only require Context as an argument. If someone could shed some light on this, that would be great.