I have the opportunity to view my application in different languages - English, Tamil and Hindi. I used customtextview where the font is installed depending on what language the user wants.
I get a memory exception when the application is used for a while. Is there any direct effect of setting the font for all text views in the application?
Attached a CustomTextView code snippet extending Textview:
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); } }
Error Log:
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)
Without the localization function, my application works fine and does not crash.
base_layout.xml:
<?xml version="1.0" encoding="utf-8"?> <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"> <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"> <ImageView android:id="@+id/header_click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/before" android:layout_alignParentRight="true" /> <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" /> <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"> <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" /> </LinearLayout> <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"> <ImageView android:id="@+id/rate_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/rate_us" /> <ImageView android:id="@+id/like_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/fb_like_us" /> <ImageView android:id="@+id/follow_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/twitter_follow_us" /> </LinearLayout> </RelativeLayout> </LinearLayout>
I install the language when the language is changed, restarts my application. But the memory is not released, and every time my application opens, it only increases when the application crashes due to low memory.
Setlocale method to change the language:
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()); }
I also found out that the size of the native heap is constantly increasing when the language changes and, finally, the application crashes.