0

My main activity calls my Surfaceview game, setting a layout with an adview and surfaceview added (initially I did not use a layout at all before I had to ad the banner). however I have not been able to access the main activity from surfaceview to change the layout so it doesn't include the adview once the game starts. i'm forced to have the banner on continually because of this. attempts to kill the ad still leaves a blank banner. does anyone know how to access main activity functions from surfaceview.

I created a removead() function in the main activity to define a new contextview without the adView, but I can't access it.

context, the main activity, is passed to the Surfaceview on creation. I've tried:

context.removead();
this.getContext().removead();
((Activity) this.getContext()).removead();
ViewGroup vg = (ViewGroup)(
this.getParent());
vg.removeView(adView);
hima
  • 610
  • 3
  • 10
  • 24
Androidcoder
  • 4,389
  • 5
  • 35
  • 50

1 Answers1

0

I ended up abandoning attempts to control the adAiew directly from surfaceView, instead creating a Handler in the main activity and sending messages to it from the surfaceView the main activity created. The handler then calls VISIBLE or GONE to the adAiew depending on the message sent.

Androidcoder
  • 4,389
  • 5
  • 35
  • 50
  • An other idea would have been to use an event bus implementation. That way you could just post messages and listen for messages. [`EventBus`](https://github.com/greenrobot/EventBus/wiki) is easy to use and popular but your solution more or less accomplishes the same as would using a `BroadcastReceiver` since Android is an event driven model to start with. – Ali Sep 12 '13 at 05:25