2

I have a share button in my application, whose purpose is to share a string of information with user selected app (for example twitter or gmail). The problem is when you click the share button, the share window appears and the app becomes black in the background. After done sharing, the user is returned to menu / home screen and has to open the app again in order to continue using it from where they left.

What I need is to go back to my app after done sharing.

This is the OnClickListener I used:

shareButton.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String text = mContext.getString(R.string.shareText) + " " + profileInfo.getName() + " " + mContext.getString(R.string.shareText2);
                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.putExtra(Intent.EXTRA_TEXT, text);
                    shareIntent.setType("text/plain");
                    startActivity(shareIntent);
                }
            }
    );

What am I doing wrong here? Any help is appreciated.

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
N. Park
  • 387
  • 4
  • 14

2 Answers2

2

Use startActivityForResult() instead of startActivity(). This will return to the starting Activity after the Intent action is completed. See the Getting a Result from an Activity post for an example.

And wait for response by overriding onActivityResult() method :

    @Override   public void onActivityResult(int requestCode, int resultCode, Intent data) {        
        // TODO Auto-generated method stub if(requestCode == 0) {
       // You will get callback here when email activity is exited
      // perform you task here 
      }
U.Swap
  • 1,921
  • 4
  • 23
  • 41
0

There is noting wrong with your share intent code which you mentioned above, although there could be some thing wrong with your onPause() method, you probably doing some thing there, try to debug the code after adding logs So you can track the issue OR put your activity code here So exact issue can be identified.

Muhammad Farhan Habib
  • 1,859
  • 20
  • 23