我嘗試在MainActivity之外顯示廣告。如果我把showAd在這個類它的工作好,並顯示我的廣告,但是當我通過實現界面我的遊戲類調用這個函數我有一個錯誤: 「要求主線程」在課堂之外撥打MainActivity功能
MMRequest request = new MMRequest(); ;
MMInterstitial interstitial;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MMSDK.initialize(this);
interstitial = new MMInterstitial(this);
interstitial.setMMRequest(request);
interstitial.setApid("xxxxxx");
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
RelativeLayout layout = new RelativeLayout(this);
View gameView = initializeForView(new JumpJackieJump(new RequestHandler(), this), cfg);
layout.addView(gameView);
setContentView(layout); }
@Override
public void showAd()
{
interstitial.fetch();
interstitial.setListener(new RequestListenerImpl()
{
@Override
public void requestCompleted(MMAd mmAd)
{
interstitial.display();
}
});
請發表較完整的代碼。上面的代碼片段並不清楚。 – 2014-12-05 13:38:07