所以我将AdMob添加到我的应用程序中,现在它不会通过按下按钮启动下一个活动。 我正在尝试按下主活动中的按钮,以便进入第二个活动。 在我添加Admob
之前它有用主要活动:
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// Create an ad.
adView = new AdView(this, AdSize.BANNER, "XXXXXXXXXXXX");
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
RelativeLayout layout = (RelativeLayout) findViewById(R.id.main1);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
/** Called before the activity is destroyed. */
@Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
Button next = (Button) findViewById(R.id.button1);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), PartyRockScreen.class);
startActivityForResult(myIntent, 0);
}
});
}
}
第二项活动:
private AdView adView2;
@Override
public void onBackPressed() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.party);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// Create an ad.
adView2 = new AdView(this, AdSize.BANNER, "XXXXXXXXXXXX");
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
RelativeLayout layout = (RelativeLayout) findViewById(R.id.party1);
layout.addView(adView2);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
// Start loading the ad in the background.
adView2.loadAd(adRequest);
}
/** Called before the activity is destroyed. */
@Override
public void onDestroy() {
// Destroy the AdView.
if (adView2 != null) {
adView2.destroy();
}
super.onDestroy();
final MediaPlayer mediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.partyrock);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
ViewFlipper mFlipper;
mFlipper = ((ViewFlipper)findViewById(R.id.flipper));
mFlipper.setAutoStart(true);
mFlipper.startFlipping();
mFlipper.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));
ViewFlipper mFlipper1;
mFlipper1 = ((ViewFlipper)findViewById(R.id.flipper1));
mFlipper1.setAutoStart(true);
mFlipper1.startFlipping();
mFlipper1.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));
mFlipper1.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));
Button next = (Button) findViewById(R.id.button2);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mediaPlayer.stop();
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
};
}
答案 0 :(得分:1)
试一试 -
Intent myIntent = new Intent(MainActivity.this, PartyRockScreen.class);
startActivity(myIntent);