user2592807
user2592807

Reputation: 374

Interstitial Ad onBackPressed from default video player

I am making a TV channel streaming app which when click on a channel from a list view it goes to another activity and a pop up of player selection comes and after selecting a player plays video. Now i am implementing admob interstitial ad which should be displayed directly onBackPressed and then after closing ad goes to my "Activity A" (first activity) and not the second activity B. It works flawelessly but when i press backbutton it goes to second activity blank screen and then on back press to ad.How i can do this to show ad on backpress from default selected video player. here is some code

Activty A

case 1:
                    i = new Intent(A.this, B.class);
                    i.putExtra("channel","http://id=HBO");
                    startActivity(i);
                    break;

Activity B

Bundle bundle = getIntent().getExtras();
    String channel = bundle.getString("channel");
    Uri uri = Uri.parse(channel);
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.setDataAndType(uri, "video/mp4");
    startActivity(intent);

and onBackPressed

@Override
public void onBackPressed() {
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
    super.onBackPressed();
}

Upvotes: 1

Views: 1107

Answers (1)

FrankR
FrankR

Reputation: 206

If the ad is loaded you show it which is fine, but you still call through to super.onBackPressed(). This causes the activity to finish and return to the last activity.

What you need to do is add an else clause which will call super.onBackPressed(); only if the ad is not loaded.

Then you need to add a listener to your interstitial ad that will listen for the ad closed event and call finish(); there.

Upvotes: 1

Related Questions