Note that there are some explanatory texts on larger screens.

plurals
  1. POout of memory exception android
    text
    copied!<p>I have an option to view my application in different languages - English,Tamil and Hindi.I have used customtextview where typeface is being set depending on what language the user wants.</p> <p>I am getting out of memory exception when the application is used for some time. Is there any direct impact of setting typeface for all the textviews in the application? </p> <p>Have attached the code snippet of CustomTextView which is extending Textview:</p> <pre><code> public L10nTextView(Context context, AttributeSet attrs) { super(context, attrs); this.ttfName = ttfFileName; init(); } private void init() { if (ttfName != null) { setTypeface(MyApplication.typeFace); } else { setTypeface(null); } } </code></pre> <p><strong>Error log:</strong></p> <pre><code>11-15 20:08:50.527: ERROR/AndroidRuntime(2731): FATAL EXCEPTION: main 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.content.res.Resources.loadDrawable(Resources.java:1709) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.content.res.Resources.getDrawable(Resources.java:581) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2226) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2261) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:203) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.Activity.setContentView(Activity.java:1657) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.techjini.tvguide.android.activity.BaseActivity.setContentView(BaseActivity.java:94) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.techjini.tvguide.android.activity.ProgramNextAiringActivity.onCreate(ProgramNextAiringActivity.java:23) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.os.Handler.dispatchMessage(Handler.java:99) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.os.Looper.loop(Looper.java:130) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at android.app.ActivityThread.main(ActivityThread.java:3683) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at java.lang.reflect.Method.invokeNative(Native Method) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at java.lang.reflect.Method.invoke(Method.java:507) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 11-15 20:08:50.527: ERROR/AndroidRuntime(2731): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Without localization feature,my application is working fine and does not crash.</p> <p>base_layout.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/header_bar_layout" android:visibility="visible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/header_bar" android:visibility="visible" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;ImageView android:id="@+id/header_click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/before" android:layout_alignParentRight="true" /&gt; &lt;ProgressBar android:id="@+id/prg_bar" android:layout_toLeftOf="@id/header_click" android:layout_width="25dip" android:layout_height="25dip" android:layout_centerVertical="true" android:visibility="gone" /&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/logo_layout" android:orientation="horizontal" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="visible"&gt; &lt;ImageView android:id="@+id/logo_bar" android:layout_alignParentLeft="true" android:layout_height="wrap_content" android:src="@drawable/logo_bar" android:layout_width="wrap_content" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/rating" android:orientation="horizontal" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="invisible"&gt; &lt;ImageView android:id="@+id/rate_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/rate_us" /&gt; &lt;ImageView android:id="@+id/like_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/fb_like_us" /&gt; &lt;ImageView android:id="@+id/follow_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/twitter_follow_us" /&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>I am setting the locale when the language is changed restart my application. But the memory is not being released and every time my application opens it only increases when finally the app crashes due to low memory.</p> <p>Setlocale method to change the locale:</p> <pre><code> public void setLocale(String languageLocaleToLoad) { Locale locale = new Locale(languageLocaleToLoad); Locale.setDefault(locale); android.content.res.Configuration config = new android.content.res.Configuration(); config.locale = locale; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } </code></pre> <p>I also found out that the native heap size keeps on increasing whenever the language is changed, and finally the application crashes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload