这是我设置壁纸的代码,其中我整合了admob intertitial但是当我按下并转到另一个活动时它会崩溃。帮我。我的logcat在setContentView(R.layout.activity_x4)上显示错误;
public class X4Activity extends Activity implements AdListener,
OnClickListener {
ImageView display, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10;
int to;
Button set, save, rate;
InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_x4);
interstitial = new InterstitialAd(this, "a15270cbf9bb519");
AdRequest adRequest = new AdRequest();
interstitial.loadAd(adRequest);
interstitial.setAdListener(this);
to = R.drawable.x24;
display = (ImageView) findViewById(R.id.zimage);
c1 = (ImageView) findViewById(R.id.x1);
c2 = (ImageView) findViewById(R.id.x2);
c3 = (ImageView) findViewById(R.id.x3);
c4 = (ImageView) findViewById(R.id.x4);
c5 = (ImageView) findViewById(R.id.x5);
c6 = (ImageView) findViewById(R.id.x6);
c7 = (ImageView) findViewById(R.id.x7);
c8 = (ImageView) findViewById(R.id.x8);
c9 = (ImageView) findViewById(R.id.x9);
c10 = (ImageView) findViewById(R.id.x10);
rate = (Button) findViewById(R.id.rate);
set = (Button) findViewById(R.id.set);
save = (Button) findViewById(R.id.save);
c1.setOnClickListener(this);
c2.setOnClickListener(this);
c3.setOnClickListener(this);
c4.setOnClickListener(this);
c5.setOnClickListener(this);
c6.setOnClickListener(this);
c7.setOnClickListener(this);
c8.setOnClickListener(this);
c9.setOnClickListener(this);
c10.setOnClickListener(this);
set.setOnClickListener(this);
rate.setOnClickListener(this);
save.setOnClickListener(this);
}
@Override
public void onReceiveAd(Ad ad) {
Log.d("OK", "Received ad");
if (ad == interstitial) {
interstitial.show();
}
}
public void onClick(View v) {
String fName;
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.x1:
display.setImageResource(R.drawable.x24);
to = R.drawable.x24;
break;
case R.id.x2:
display.setImageResource(R.drawable.x25);
to = R.drawable.x25;
break;
case R.id.x3:
display.setImageResource(R.drawable.x26);
to = R.drawable.x26;
break;
case R.id.x4:
display.setImageResource(R.drawable.x27);
to = R.drawable.x27;
break;
case R.id.x5:
display.setImageResource(R.drawable.x28);
to = R.drawable.x28;
break;
case R.id.x6:
display.setImageResource(R.drawable.x29);
to = R.drawable.x29;
break;
case R.id.x7:
display.setImageResource(R.drawable.x30);
to = R.drawable.x30;
break;
case R.id.x8:
display.setImageResource(R.drawable.x31);
to = R.drawable.x31;
break;
case R.id.x9:
display.setImageResource(R.drawable.x32);
to = R.drawable.x32;
break;
case R.id.x10:
display.setImageResource(R.drawable.x33);
to = R.drawable.x33;
break;
case R.id.set:
***********
case R.id.save:
**********
}
}
@Override
public void onBackPressed() {
X4Activity.this.finish();
}
@Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
考虑到你知道为什么需要这个,请你告诉我你为什么需要:
@Override
public void onBackPressed() {
X4Activity.this.finish();
}
您正在终止“主要”活动。