mercredi 15 avril 2015

Random background? Android

I'm trying to set random bg for my activity, but my app is force close when I get in my activity. What is the problem with this code?


In my first activity, you get the camera intent after clicking the START button, and when you take the picture about yourself, you get to a another activity, where for result you get a random image answer in the bg. It's like a application where you take a pic about yourself, and the program will answer for you that you're looking good, or not, something like that. The answer is provided as an image, in the imageView, and this is why I need random bg change.



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int[] images = {R.drawable.image01, R.drawable.image02, R.drawable.image03};

setContentView(R.layout.activity_main_activity2);
ImageView mImageView = (ImageView)findViewById(R.id.imageView);

// Get a random between 0 and images.length-1
int imageId = (int)(Math.random() * images.length);

// Set the image
mImageView.setBackgroundResource(images[imageId]);

// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-012012013013/01201201201");

// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();

// Begin loading your interstitial.
interstitial.loadAd(adRequest);
}


So what is the problem? I get no error for the code, just force close, when I take the picture, and get in to the another activity.





Aucun commentaire:

Enregistrer un commentaire