6

My app opens a browser activity via startActivity(). Can I close that browser activity if I feel like it?

For one thing, startActivity() does not return anything - can I get an Activity object back from it somehow?

In the JavaScript world, the convention is that whoever opened a new browser window has the authority to close it. Just sayin'.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281

4 Answers4

4

I think you getting hopefully answer from this post

Starting an ACTION_VIEW activity to open the browser, how do I return to my app?

Clear back stack after activity is opened from web-browser by url "appname://com.appname/"

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159
3

No you can't. You don't have control over browser activity. You can use WebView to embed the browser in custom activity on which you'll have full control and call finish() when you want.

Mojo Risin
  • 8,136
  • 5
  • 45
  • 58
  • +1 I'll think of it... does not quite fit my scenario, since I don't want to replicate Refresh, Go, Back/Forward and the rest of the browser framing. – Seva Alekseyev Aug 04 '11 at 01:48
2

As outlined here, if you activate the root activity with the following intent flags:

Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP

it will finish all activities on top of it in the navigation stack. Including the browser.

Community
  • 1
  • 1
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
1

No you can not get a handle for the Activity object.


VERY DANGEROUS

Try using a Handler or any other way to send a backspace key which usually closes the activity. Will it work?

However keep in mind that this is completely wrong

Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106