How to get back to initial app where the implicit

2019-08-08 09:46发布

问题:

I have an app which contain some buttons.some of these buttons open specific URL/address by android internet browser and close my app(implicit intent). but i want this, when user close internet browser android redirect user to my app automatically.

my button code is:

          case R.id.btnB:
              Uri myurl1 = Uri.parse("http://www.justandroid.com/");
              Intent intent_B = new Intent(Intent.ACTION_VIEW, myurl1 );
              startActivityForResult(intent_B,8);
              break;

          case R.id.btnC:
              Uri myurl2 = Uri.parse("http://www.loveandroid.com/");
              Intent intent_C = new Intent(Intent.ACTION_VIEW, myurl2 );
              startActivityForResult(intent_C,7);
              break;

and in onActivityResult :

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);


    if(requestCode==7)
    {
               //do what
            }
    if(requestCode==8)
    {
               //do what
            }

these code works good,but how to change them to what i want.thanks//

回答1:

Instead of startActivity use startActivityForResult. You can even override onActivityResult method to know when the user returned from other activity.