Android: sharing (something) using Intent.ACTION_SEND, then automatically returning to my application

I would like to share something from my application. When it is sent (for example, a message has been sent), I want my application to reactivate and the send application to disappear. Using the code below, I expected onActivityResult be called, but it never gets called.

After sending the email, my application appears again, but after sending the SMS ("Messages") the messaging application remains. ( onActivityResult 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(); 
+4
source share
1 answer

This will only be called if the user clicks the back button. Because you are starting a new intention, so you are giving control of another application. Therefore, usually, if the user clicks the "Back" button (which I will do as an Android user), the user will return to your application. This is what I would prefer to use for this case, and as far as I know, this is the only way to do this in Android.

+7
source

Source: https://habr.com/ru/post/1437565/


All Articles