So, I'm integrating with Flurry and trying to figure out when to call FlurryAgent.onEndSession(this);
.
I have four activities in my app. As there is currently only one entry point/activity adding FlurryAgent.onStartSession(this, Globals.FLURRY_API_KEY);
is easy. But the problem with stopping the session is the app can be closed from any one of the four activities. Also, onStop()
is called each time the app changes the activity on screen.
Has suggestions on how to decide when to end the Flurry session? Taking some advice from another answer, I could use a BaseActivity
class and each of my four activities would extend this, I would then place onStart()
and onStop()
in there. This would solve the issue of littering my code with Flurry start/stop calls but not the issue of when to stop.
My current solution is to build on the above approach and add an exit flag. The base activity will only end the Flurry session if the exit flag is set to true.
Then, in each activity I will look catch key presses such as the back button and home key. If the home or back key is pressed I will set exit to true.
This should have the correct effect but I feel it's a bit hacky.
iOS is nice, where you only need to start the session. It would probably be a good idea to refactor my four activities into one and use Fragments. What do you guys think?