The Android intent system is great. I want to let the user select an image they have taken so I can do something with it? I want to get contact details of one of the user's contacts? I want to let the user send an email? I don't have to write all that myself. Use an intent. Great!
However I have a complaint. I'm working on a feedback form within the app.
It's nothing fancy, just a handful of text fields basically, which are then
bunged in an email and so all the user has to do is hit "send" in the email
app of their choice. But I don't want
the user to lose the stuff they've entered if they hit home, answer a call, etc.
so I store the text in shared preferences in
onPause() and bring it back in
onResume(). When the user sends the email I'll delete the text from
the shared preferences so it doesn't hang around. Looks
startActivityForResult() right? Well as it turns out... no.
If the user has more than one app installed, when they hit the send button they
get to choose which one they want to use. If they hit back instead of choosing
an app the result code in
onActivityResult() is 0 which is
Ok, that looks good. The user didn't get as far as the email app. I'd better
keep their data.
If the user gets as far as the email app and then discards the email instead of
sending it, the result code is also
RESULT_CANCELLED. Fair enough I suppose.
They didn't actually send the email. Still keeping their data in shared prefs.
So what's the result code if the user sends the email?
I tried this with GMail which I would expect to be the gold standard. If GMail
doesn't do it then it doesn't really matter if every other email app in the Play
Store does it right; I can't rely on the result code from the most popular email
client on our platform.
So I've got no way to tell the difference between user didn't even get as far as their email app and user sent the email. So I can't clear the data from the shared preferences. Not great.
So a plea. To anyone who is going to handle an Intent from other apps to
perform some action. Please, please, please make sure you
something useful if
you successfully perform the action. Make life nice for us users of your
Darren @ Æ