2011-11-15 23 views
4

英語、タミール語、ヒンディー語などのさまざまな言語でアプリケーションを表示するオプションがあります。ユーザーが希望する言語に応じて書体が設定されているcustomtextviewを使用しています。メモリ不足例外android

アプリケーションをしばらく使用するとメモリ不足例外が発生します。アプリケーションのすべてのテキストビューの書体設定に直接影響はありますか?

はのTextViewを拡張さCustomTextViewのコードスニペットを添付しました:

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); 
    } 

} 

エラーログ:

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) 

をローカライズ機能がなければ、私のアプリケーションが正常に動作しているとクラッシュしていません。

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> 

私はロケールを設定しています。しかし、メモリは解放されていませんし、アプリケーションが開くたびに、メモリが足りなくなって最終的にアプリケーションがクラッシュすると増加します。

ロケールを変更するにsetlocale方法:

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()); 

} 

私はまた、ネイティブヒープサイズは、言語が変更されるたびに増加し、最終的にアプリケーションがクラッシュし続けていることが分かりました。

+1

エラーログを投稿できますか? – user370305

+0

BaseActivityのレイアウト、またはBaseActivityの94行目にロードされているレイアウトを投稿できますか? –

+0

あなたの問題は実際にはどこか他の場所、つまり書体とは関係がないと思われます。ロケールの変更は、単にメモリ不足の問題をあなたの注意を引くことです。他に何が覚えていますか?あなたはDDMSを使って見つけることができます。 –

答えて

0

メモリアナライザーツール(MAT)は、メモリがどこに行くのかを調べるのに役立ちます。多くの場合、実際の問題が発生している場所でクラッシュが発生することはありません。

http://eclipse.org/mat/

あなたは、EclipseでのDDMSビュー(「更新ヒープ」ボタンを使用して、ガベージコレクションをトリガー)から直接メモリをダンプすることができます。このツールを理解するには少し時間がかかるかもしれませんが、あなたの武器の中にあることは重要です。

私は、ロケールに関連するメモリ不足例外の問題もあります。私の問題は、ロケールを変更するためにアクティビティをリロードし、あるインスタンスでは新しいロケールのロードに失敗し、メモリが不足するまでリロードを続けたことでした。

+0

私はいくつかのリストビューを持っています。言語が設定されると、アプリケーションを再起動します。 Intent i = getBaseContext()。getPackageManager() .getLaunchIntentForPackage(getBaseContext()。getPackageNam()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); しかし、アプリケーションがリロードされても、割り当てられた前のメモリは解放されません。 – Maggi

+0

あなたはその努力に行く必要がありますか?私はちょうどこれを行う:インテントrestartIntent =新しいインテント(this、this.getClass()); restartIntent.setAction(Intent。ACTION_CONFIGURATION_CHANGED); startActivity(restartIntent); finish(); – ProjectJourneyman