<summary>
Is there an elegant way of getting the result of an activity from a non-activity class, or is it always going to be a hack? Would I be better avoiding that situation if possible?
</summary>
I have an activity, that has an instance of a session for a web service, which will generally be pre-authenticated (the session key will be saved in SharedPreferences). However, the first time it runs, I will need to pop up a log in activity, which will return the username and password to the session, which will then talk to the server and get a session key.
Ideally, I would like to have the non-activity session class call startActivityForResult, but I'm not sure it's possible. I've seen various questions about how it can be done:
How to get the result from OnActivityResult inside another class?(outside of the activity
use startActivityForResult from non-activity
But they all seem a little hacky. I've also seen this, which suggests that passing round contexts is not the best idea anyway:
http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html
Another option is to save the username and password to sharedpreferences and retrieve it in the other class, but then I'd have to have some way of figuring out when it had been saved, and it all seems to be getting rather messy.
Another option is to make the session a non-displaying activity. Seems like a large overhead though.
My project is still in planning stages, so I'm after best practice. What is the most elegant way to do this?