2012-04-06 59 views
0

因此,我將AdMob添加到了我的應用中,現在它不會通過按下按鈕來開始下一個活動。 我試圖按下主要活動中的一個按鈕,以便它進入第二個活動。 它的工作之前,我加入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

用的ActivityGroup嘗試... – 2012-04-06 12:12:01

+0

這不是一個非常有用的答案.. – SnoX 2012-04-06 12:17:45

回答

1

試試吧 -

+0

沒關係固定它.. – SnoX 2012-04-06 13:39:48

+0

@SnoX,怎麼樣?我有同樣的問題 – 2012-09-05 05:49:29

+0

@dhomes,讓我看看你的代碼:-) – SnoX 2012-09-05 12:08:56