title: How to fit a background image to the screen of an Android device
body: <p>I am using Eclipse to write an Android app. I want my app to display a background image which is stretched to the size of the screen.</p>
  
  <p>I have written the following code, but in the emulator it immediately exited the app when I ran it. Could someone please help me to understand the problem...</p>
  
  <p>Here is my code...</p>
  
  <pre><code>public class Roller extends Activity {
  
      Display display = getWindowManager().getDefaultDisplay(); 
      int dwidth = display.getWidth();
      int dheight = display.getHeight();
      Bitmap background1 = BitmapFactory.decodeResource(getResources(),R.drawable.sunnybackground);
      Bitmap BSunny = Bitmap.createScaledBitmap(background1,dwidth,dheight,true);
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(new Panel(this));
      }
  
      class Panel extends View {
          public Panel(Context context) {
              super(context);
          }
  
          public void onDraw(Canvas canvas) {
              canvas.drawBitmap(BSunny, 0, 0, null);
          }
      }
  }
  </code></pre>