0

I am developing an application in which i am sharing URL from my app with the help of share intent as:

final Intent intentShare = new Intent(Intent.ACTION_SEND);
intentShare.setType("text/plain");
intentShare.putExtra(Intent.EXTRA_TEXT, "www.google.com");              
try {
    startActivity(Intent.createChooser(intentShare, "Select an action"));
} catch (android.content.ActivityNotFoundException ex) {
    // (handle error)
}

need of application is that :

After sharing the link by share intent a new intent should call to navigate on second screen.

How to do that?.

Ajinkya
  • 1,057
  • 7
  • 18
Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95
  • You could try inserting the other intent in the Finally block of your Try? – Ron Feb 09 '16 at 08:45
  • Just an idea: Instead of startActivity could you use startActivityForResult() and call the 2nd activity in onActivityResult()? – Christopher Feb 09 '16 at 08:48
  • @Ron: Finally code block execute first then share intent. So it is of no use. – Manoj Fegde Feb 09 '16 at 08:50
  • @Christopher - Your suggesion will not work, since it is explicit intent call. It will always return RESULT_CANCEL when explicit intent call is made with Intent.ACTION_SEND. Since you can not capture the Explicit activity, ActivityForResult will not help. To me the feasibility of handling result on explicit intent is NILL unless you implement some call back at Framework layer on your activity as well as explicit activity, – Rakesh Feb 09 '16 at 08:52
  • @Rakesh - maybe instead of checking for the result or code, you can insert an Intent extra and check for that? – Ron Feb 09 '16 at 09:06
  • @Ron - Yes you can add extras, but the problem is how you will make sure that content is shared successfully. Since you are out of your sand box, how would you control explicit call to complete share and change your extras to parse and process. You may be right if the intention is to check whether share button is clicked and open, irrespective of successful share. I hope I am clear in narrating the logic ... – Rakesh Feb 09 '16 at 09:10
  • @Rakesh - Yeah I got your point, but it seems there are no trigger points after share intent. :) – Ron Feb 09 '16 at 09:14
  • @Ron - Yes, there can never be trigger points inside other process unless your app has a knowledge of other process. I have seen some answers given with implementation of ActivityForResult but this is not the correct way. I would never handle or track user's action out of my app. – Rakesh Feb 09 '16 at 09:18

1 Answers1

1

Try this: after the share, call a start to your second activity

  1. define a key:

    private int myKeyForResult = 3;

2 start your share intent for result:

try {
    startActivityForResult(shareIntent, myKeyForResult);
    Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);

} catch (android.content.ActivityNotFoundException ex) {
    // (handle error)
}
  1. wait for the result of the share and start the 2nd activity:

    @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); myIntent.putExtra("key", value); //Optional parameters CurrentActivity.this.startActivity(myIntent); }

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • This took me to next screen before sharing the url. The need is after sharing the url it should take me to next screen. – Manoj Fegde Feb 09 '16 at 09:00