Reputation: 11050
I have a video player that displays ads. When I click on the video player I fire a Intent that opens a URL. However, if there's many apps that can handle that Intent, a dialog is displayed. Is there a reliable way to know if the user has dismissed that dialog so I can resume the ad?
Upvotes: 2
Views: 918
Reputation: 7082
Opening the picker dialog will call the onPause()
method of the Activity. Closing it will call the onResume()
method.
Simply pause and resume your ad video in those methods.
Upvotes: 0
Reputation: 4123
This will do the trick:
Fire the intent using startActivityForResult
, like this
private static final Integer OPEN_BROWSER_REQUEST_CODE = 100;
[...]
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivityForResult(browserIntent, OPEN_BROWSER_REQUEST_CODE);
and then catch the result by overriding onActivityResult
, like this
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OPEN_BROWSER_REQUEST_CODE) {
switch (resultCode) {
case RESULT_OK:
break;
case RESULT_CANCELED:
break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
Hope this helps
Upvotes: 3
Reputation: 30611
You must be launching the Intent
like this:
startActivity(intent);
You need to launch it like this:
static final int OPEN_AD = 1234;
startActivityForResult(intent, OPEN_AD);
and catch the dismissal in
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OPEN_AD) {
/* If user dismisses diaog */
if (resultCode =! RESULT_OK) {
/* display ad again etc... */
}
}
}
Upvotes: 2