Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Sharing (something) via Intent.ACTION_SEND, then automatically return to my app

I would like to share something from my application. Once it is shared (e.g - message sent), I want my application to be active again and the sending app to disappear. Using the code below, I expected onActivityResult to be called, but it is never called.

After sending email, my application appears again, but after sending SMS ('Messaging') the messaging app remains. (onActivityResult is never called)

Thanks :-)

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain"); 
String shareBody = "This is a test";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "You have to see this!");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);

startActivityForResult(Intent.createChooser(sharingIntent, "Share via"),1);

getFragmentManager().popBackStack();
like image 787
JRun Avatar asked Oct 03 '12 11:10

JRun


1 Answers

This will only be called if the user presses the back button. Because you are starting a new intent, so you give control to another application. So normally, if the user presses the back button (which I would do as an Android user) the user will go back to your app. This the way I would prefer to use for this case, and as far as I know it is also the only way to do this in Android.

like image 97
ndsmyter Avatar answered Sep 27 '22 17:09

ndsmyter