如何返回到隐式意图开始的初始应用程序?

问题描述:

我有一个包含一些按钮的应用程序.其中一些按钮通过android网络浏览器打开特定的URL/地址并关闭我的应用程序(隐式意图). 但是我想要这个,当用户关闭互联网浏览器时,android会自动将用户重定向到我的应用.

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.

我的按钮代码是:

          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;

和onActivityResult中:

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//

使用startActivityForResult代替startActivity.您甚至可以覆盖onActivityResult方法,以了解用户何时从其他活动返回.

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