2012-03-26 3 views
1

첫 번째 Android 앱을 제작 중이며 Leadbolt 잠금 장치를 구현하려고합니다. Leadbolt 문서와 같은 모든 것을 수행했지만 앱을 실행하면 항상 충돌합니다. public class FullActivity extends Activity implements AdListener에서 AdListener를 제거하면 모든 것이 작동합니다. Intent full = new Intent(GridActivity.this, FullActivity.class); 일 때 응용 프로그램이 중단되고 super.onCreate(savedInstanceState); 중단 점에도 가지 않습니다. 이 FullActivity.java입니다 : 우리는 당신을 위해이 문제를 해결해야하는 코드를 일부 조정을 한Android 앱에서 Leadbolt 구현

import java.io.IOException; 
import android.app.Activity; 
import android.app.WallpaperManager; 
import android.content.SharedPreferences; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.widget.Toast; 

import com.Leadbolt.AdController; 
import com.Leadbolt.AdListener; 

public class FullActivity extends Activity implements AdListener{ 
private AdController myController; 
private String MY_LB_SECTION_ID="1111111"; 

private Integer[] mThumbIds = { 
     R.drawable.p1, 
     R.drawable.p2, 
     R.drawable.p3, 
     R.drawable.p4, 
     R.drawable.p5, 
     R.drawable.p6, 
     R.drawable.p7, 
     R.drawable.p8, 
     R.drawable.p9, 
     R.drawable.p10, 
     R.drawable.p11, 
     R.drawable.p12, 
     R.drawable.p13, 
     R.drawable.p14, 
     R.drawable.p15, 
     R.drawable.p16, 
     R.drawable.p17, 
     R.drawable.p18, 
     R.drawable.p19, 
     R.drawable.p20, 
     R.drawable.p21, 
     R.drawable.p22, 
     R.drawable.p23, 
     R.drawable.p24, 
     R.drawable.p25, 
     R.drawable.p26, 
     R.drawable.p27, 
     R.drawable.p28, 
     R.drawable.p29, 
     R.drawable.p30, 
     R.drawable.p31, 
     R.drawable.p32, 
     R.drawable.p33, 
     R.drawable.p34, 
     R.drawable.p35, 
     R.drawable.p36, 
     R.drawable.p37, 
     R.drawable.p38, 
     R.drawable.p39, 
     R.drawable.p40, 
     R.drawable.p41, 
     R.drawable.p42, 
     R.drawable.p43, 
     R.drawable.p44, 
     R.drawable.p45, 
     R.drawable.p46, 
     R.drawable.p47, 
     R.drawable.p48, 
     R.drawable.p49, 
     R.drawable.p50 
}; 

Integer imageId; 
TouchImageView touch; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    final Activity act = FullActivity.this; 
    final AdListener listener = FullActivity.this; 
    super.onCreate(savedInstanceState); 

    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     imageId = extras.getInt("image"); 
     touch = new TouchImageView(this); 
     Bitmap snoop = BitmapFactory.decodeResource(getResources(), mThumbIds[imageId]); 
     touch.setImageBitmap(snoop); 
     touch.setMaxZoom(4f); //change the max level of zoom, default is 3f 
     setContentView(touch); 
    } 

    final String PREFS_NAME = "AppPrefs"; 

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
    int ad = settings.getInt("ad", 0); 

    if((imageId > 25)&&(ad < 1)){ 

     touch.post(new Runnable() { 
      public void run(){ 
       myController = new AdController(act, MY_LB_SECTION_ID, 
         listener); 
       myController.loadAd(); 
      } 
     }); 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.main_menu, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle item selection 
    switch (item.getItemId()) { 
     case R.id.set_back: 
      setBack(); 
      return true; 
     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 

private void setBack() { 
    WallpaperManager myWallpaperManager 
    = WallpaperManager.getInstance(getApplicationContext()); 
    try { 
      myWallpaperManager.setResource(mThumbIds[imageId]); 
    } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
    Toast.makeText(FullActivity.this.getApplicationContext(), "Wallapers set!", Toast.LENGTH_SHORT).show(); 
} 


public void onDestroy(){ 
    myController.destroyAd(); 
    super.onDestroy(); 
} 

public void onAdClicked() {} 

public void onAdClosed() {} 

public void onAdCompleted() { 
    // TODO Auto-generated method stub 
    SharedPreferences settings = getSharedPreferences("AppPrefs", 0); 
    SharedPreferences.Editor editor = settings.edit(); 
    editor.putInt("ad", 1); 

    // Commit the edits! 
    editor.commit(); 
} 

public void onAdFailed() { 
    this.runOnUiThread(new Runnable() { 
     public void run() { 
      if(myController != null){ 
       myController.destroyAd(); 
      } 
     } 
    }); 
} 

public void onAdLoaded() {} 

public void onAdProgress() {} 

}

답변

2

.

package com.mkstudio.hdwallpapers; 
import java.io.IOException; 

import android.app.Activity; 
import android.app.WallpaperManager; 
import android.content.SharedPreferences; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.widget.Toast; 

import com.Leadbolt.AdController; 
import com.Leadbolt.AdListener; 

public class FullActivity extends Activity{ 
private AdController myController; 
private String MY_LB_SECTION_ID="729926945"; 

// references to our images 
private Integer[] mThumbIds = { 
     R.drawable.p1, 
     R.drawable.p2, 
     R.drawable.p3, 
     R.drawable.p4, 
     R.drawable.p5, 
     R.drawable.p6, 
     R.drawable.p7, 
     R.drawable.p8, 
     R.drawable.p9, 
     R.drawable.p10, 
     R.drawable.p11, 
     R.drawable.p12, 
     R.drawable.p13, 
     R.drawable.p14, 
     R.drawable.p15, 
     R.drawable.p16, 
     R.drawable.p17, 
     R.drawable.p18, 
     R.drawable.p19, 
     R.drawable.p20, 
     R.drawable.p21, 
     R.drawable.p22, 
     R.drawable.p23, 
     R.drawable.p24, 
     R.drawable.p25, 
     R.drawable.p26, 
     R.drawable.p27, 
     R.drawable.p28, 
     R.drawable.p29, 
     R.drawable.p30, 
     R.drawable.p31, 
     R.drawable.p32, 
     R.drawable.p33, 
     R.drawable.p34, 
     R.drawable.p35, 
     R.drawable.p36, 
     R.drawable.p37, 
     R.drawable.p38, 
     R.drawable.p39, 
     R.drawable.p40, 
     R.drawable.p41, 
     R.drawable.p42, 
     R.drawable.p43, 
     R.drawable.p44, 
     R.drawable.p45, 
     R.drawable.p46, 
     R.drawable.p47, 
     R.drawable.p48, 
     R.drawable.p49, 
     R.drawable.p50 
}; 

Integer imageId; 
TouchImageView touch; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.full); 

    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     imageId = extras.getInt("image"); 
     touch = new TouchImageView(this); 
     Bitmap snoop = BitmapFactory.decodeResource(getResources(), mThumbIds[imageId]); 
     touch.setImageBitmap(snoop); 
     touch.setMaxZoom(4f); //change the max level of zoom, default is 3f 
     setContentView(touch); 
    } 

    final String PREFS_NAME = "SexyRec"; 

    final Activity act = this; 

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
    int ad = settings.getInt("ad", 0); 

    if((imageId > 25)&&(ad < 1)){ 

     touch.post(new Runnable() { 
      public void run(){ 
       myController = new AdController(act, MY_LB_SECTION_ID, new AdListener() {     
        public void onAdProgress() { 
         // TODO Auto-generated method stub 

        }      
        public void onAdLoaded() { 
         // TODO Auto-generated method stub 

        }      
        public void onAdFailed() { 
         // TODO Auto-generated method stub 

        }      
        public void onAdCompleted() { 
         // TODO Auto-generated method stub 
         SharedPreferences settings = getSharedPreferences("SexyRec", 0); 
         SharedPreferences.Editor editor = settings.edit(); 
         editor.putInt("ad", 1); 

         // Commit the edits! 
         editor.commit(); 

        }      
        public void onAdClosed() { 
         // TODO Auto-generated method stub 

        }      
        public void onAdClicked() { 
         // TODO Auto-generated method stub 

        } 
       }); 
       myController.loadAd(); 
      } 
     }); 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.main_menu, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle item selection 
    switch (item.getItemId()) { 
     case R.id.set_back: 
      setBack(); 
      return true; 
     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 

private void setBack() { 
    //chuckNorris.setResourceAsWallpaper(mThumbIds[imageId]); 
    WallpaperManager myWallpaperManager 
    = WallpaperManager.getInstance(getApplicationContext()); 
    try { 
      myWallpaperManager.setResource(mThumbIds[imageId]); 
    } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
    Toast.makeText(FullActivity.this.getApplicationContext(), "Wallapers set!", Toast.LENGTH_SHORT).show(); 
} 


public void onDestroy(){ 
    myController.destroyAd(); 
    super.onDestroy(); 
} 

}