Android how to close an intent?

2019-08-07 19:12发布

问题:

I've created an intent using

browserIntent   =new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));

How do I close it? Is it

browserIntent.close 

or something... perhaps

browserIntent.finish();  ?

回答1:

You cannot close another application's activities.



回答2:

You can't.

Your intent starts a new application - browser. You can not close that application (browser) from with your activity.

Workarounds:

  1. You could however put you activity in front from a service (call intent on your activity). The question is based on what user activity would you do that, since you are not receiving user events in service.

  2. If you need user to view some web sites, you could use WebView. This is basically embedded browser that you can control.



回答3:

You can't close an intent. An Intent is just what it says - an intent, i.e. something you would like to. An intent by itself doesn't do anything. You're probably refering to an activity, which is the result of calling startActivity on an Intent.

You can't close somebody else's activity. You can just start a new one.