1

I'm facing a problem in my Android application, I need to share text on twitter and finish the current activity and start a new one after share is done I tried startActivityForResult but it doesn't work any help please.

getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity");
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, url);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        startActivityForResult(intent,0);
Aboulfotoh
  • 153
  • 1
  • 9

2 Answers2

0

As per developer doc

http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND

Action SEND: "Deliver some data to someone else. Who the data is being delivered to is not specified; it is up to the receiver of this action to ask the user where the data should be sent".

Output: nothing.

OnActivityResult wont give any output regarding the status for this intent

Deniz
  • 12,332
  • 10
  • 44
  • 62
  • Thanks for your comment, but I need a solution how can I finish current activity and start a new one after sharing? – Aboulfotoh Aug 28 '14 at 08:35
  • check this http://stackoverflow.com/a/17501704/3020568. You need to implement it using twitter4j or something like that – Deniz Aug 28 '14 at 08:39
0

I solved it by starting the the new activity then finishing the current activity then starting twitter app and share my tweet:

Intent i = new Intent(context,SecondActivity.class);
        startActivity(i);
        getActivity().finish();

        getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity");
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, url);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        startActivityForResult(intent,0);
Aboulfotoh
  • 153
  • 1
  • 9