bitmap size exceeds VM budget
<p>I've read many of the posts regarding this issue and I can't find one that would apply to my code (or at least that I can make the relation to).  </p>

<p>I have a homescreen widget that displays in both landscape and portrait.  If I continuously change the orientation of the device I get this in my logcat:</p>

<blockquote>
  <p>03-08 10:41:35.793: ERROR/dalvikvm-heap(1159): 4707316-byte external allocation too large for this process.<br>
  03-08 10:41:35.793: ERROR/GraphicsJNI(1159): VM won't let us allocate 4707316 bytes<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159): updateAppWidget couldn't find any view, using error view<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159): android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.LinearLayout<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.widget.RemoteViews.apply(RemoteViews.java:930)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:155)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:218)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at com.android.launcher2.Launcher.bindAppWidget(Launcher.java:2393)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at com.android.launcher2.LauncherModel$Loader$LoaderThread$7.run(LauncherModel.java:1051)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at com.android.launcher2.DeferredHandler$Impl.handleMessage(DeferredHandler.java:48)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.os.Handler.dispatchMessage(Handler.java:99)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.os.Looper.loop(Looper.java:123)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.app.ActivityThread.main(ActivityThread.java:4645)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at java.lang.reflect.Method.invokeNative(Native Method)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at java.lang.reflect.Method.invoke(Method.java:521)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at dalvik.system.NativeStart.main(Native Method)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159): Caused by: java.lang.reflect.InvocationTargetException<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.widget.LinearLayout.(LinearLayout.java:115)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at java.lang.reflect.Constructor.constructNative(Native Method)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     ... 19 more<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.Bitmap.nativeCreate(Native Method)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.content.res.Resources.loadDrawable(Resources.java:1718)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.View.(View.java:1885)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.View.(View.java:1834)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     at android.view.ViewGroup.(ViewGroup.java:285)<br>
  03-08 10:41:35.793: WARN/AppWidgetHostView(1159):     ... 23 more</p>
</blockquote>

<p>My code is this which utilizes remoteViews:</p>

<pre><code>    public class WidgetLayoutBuilder {

 public static final String DEG = "\u00B0";

 public static final int LAYOUT_CURRENT  = 1000;
 public static final int LAYOUT_FORECAST = 1001;

 /**
  * Constructs current conditions layout.
  *  
  * @param context
  * @param wd
  * @return
  */
 public static RemoteViews buildCurrentLayout(Context context, int appWidgetId, ACCUWX_WeatherData wd){
  Log.d("########", "remoteViews buildCurrentLayout");
  // Return object
  RemoteViews toRet = new RemoteViews(context.getPackageName(), R.layout.widget_current_layout);

  String cityText = wd.getCityName();
  String tempUnits = wd.getMetric() == 0 ? "F" : "C";
  String iconId   = "icon_" + wd.getCurrentIconCode();

  // Populate views with weather data
  toRet.setTextViewText  (R.id.current_location_text,  cityText);
  toRet.setTextViewText  (R.id.current_temp_text,   wd.getCurrentTemperature() + DEG + tempUnits);
  toRet.setTextViewText  (R.id.current_conditions_text, wd.getCurrentConditions());
  toRet.setImageViewResource (R.id.current_condition_image,  ACCUWX.getDrawableId(iconId));
  toRet.setTextViewText  (R.id.current_hi_temp,    context.getString(R.string.hi) + ": " + wd.getForecast().get(0).getDailyHigh() + DEG);
  toRet.setTextViewText  (R.id.current_lo_temp,    context.getString(R.string.lo) +": " + wd.getForecast().get(0).getDailyLow() + DEG);

  // Make alert icon visible if necessary.
  int visibility = wd.getAlertIsActive() == 0 ? View.INVISIBLE : View.VISIBLE;
  toRet.setViewVisibility(R.id.alert_icon, visibility);

  if (MainActivity.mLocations == null)
   MainActivity.mLocations = new ArrayList&lt;String&gt;();
  if (MainActivity.mLocName == null)
   MainActivity.mLocName = new String("");


  if (!MainActivity.mLocations.contains(wd.getZipCode()) || !MainActivity.mLocName.contains(wd.getCityName()))
   MainActivity.mLocations.add(wd.getZipCode());

  MainActivity.isFromLocationSearchActivity = false;

  // Launch SimpleWeather application intent
  Intent intentAppLaunch = new Intent(context, MainActivity.class);
  intentAppLaunch.putExtra(ACCUWX.Extras.LOCATION_CODE, wd.getZipCode());
  intentAppLaunch.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  PendingIntent pendingAppLaunch = PendingIntent.getActivity(context, appWidgetId, intentAppLaunch, PendingIntent.FLAG_CANCEL_CURRENT);
  toRet.setOnClickPendingIntent(R.id.current_layout, pendingAppLaunch);

  return toRet;
 }

 /**
  * Returns pretty names for display purposes in the form 'city name, state name' for the US and 'cityname, countryname (region)' for other countries.
  * @return
  */
 public static String getPrettyName(ACCUWX_WeatherData wd){
         String prettyName = "null";

         String state = wd.getStateName();
         String city = wd.getCityName();
         String country = wd.getCountryName();
         String countryCode = wd.getCountryCode();

         if (countryCode.equalsIgnoreCase("us"))
          prettyName = city + ", " + state;
         else
          prettyName = city + ", " + country + " (" + state + ")";

         return prettyName;
 }


 /**
  * Constructs deleted layout.
  * 
  * @param context
  * @return
  */
 public static RemoteViews buildDeletedLayout(Context context){
  Log.d("########", "remoteViews buildDeletedLayout");
  return new RemoteViews(context.getPackageName(), R.layout.widget_deleted_layout);

 }

}
</code></pre>

<p>Could the bitmap error be coming from the device itself and not an issue of my application?</p>

<p>Any help or direction is greatly appreciated!</p>
