0
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("plain/text");
shareIntent.putExtra(Intent.EXTRA_TEXT, text)
startActivity(Intent.createChooser(shareIntent, "Share using"));

I have 2 activity in my android app. In the second activity I have listview to show some data with images. I'm using the code above to share selected item from listview. It opens share intent chooser to choose which app to share. But when i press back button or outside of the share intent chooser, it turns back to 1st activity instead of disappering intent chooser and staying at the 2nd activity. What is the problem I cannot solve and found similar problem on the internet...

1
  • please share your activity on result code may be you are finishing your second activity
    – farrukh
    Jul 1, 2013 at 9:20

3 Answers 3

1

try finish the current activity on back press

@Override
public void onBackPressed() {
    super.onBackPressed();
            this.finish();
}
1

Try this,

@Override
public void onBackPressed() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("plain/text");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.putExtra(Intent.EXTRA_TEXT, text)
startActivity(Intent.createChooser(shareIntent, "Share using"));
this.finish();
}
0

this code will work perfect

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("plain/text");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.putExtra(Intent.EXTRA_TEXT, text)
startActivity(Intent.createChooser(shareIntent, "Share using"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.