3

I'm trying to create a live wallpaper in Android. It has a text drawn on it in the following way, with customs string placed in the assets directory:

String path = "fonts/calligraffiti.ttf";
AssetManager a1 = getApplicationContext().getAssets();
Typeface typef = Typeface.createFromAsset(a1, path);
mp1.setTypeface(typef);

mp1 is a Paint here. Drawing this is in the following way, and this is updated every second:

c.drawText(Integer.toString(t.get(Calendar.HOUR)), wt/2-5*wt/100, ht/2+sec*60+ht/15, mp1);

Every few seconds I see the following in Logcat:purging 41K from font cache [6 entries], and similar stuff Then after a few purges like that the live wallpaper service stops and restarts:

01-02 13:31:59.344: I/ActivityManager(1319): Process ca.jvsh.livewallpaper (pid 3444) has died.
01-02 13:31:59.375: W/WallpaperService(1319): Wallpaper service gone: ComponentInfo{ca.jvsh.livewallpaper/ca.jvsh.livewallpaper.LiveWallpaper}
01-02 13:31:59.383: I/WindowManager(1319): WIN DEATH: Window{457c0628 ca.jvsh.livewallpaper.LiveWallpaper paused=false}
01-02 13:31:59.391: W/ActivityManager(1319): Scheduling restart of crashed service ca.jvsh.livewallpaper/.LiveWallpaper in 5000ms
01-02 13:31:59.508: I/ActivityManager(1319): Low Memory: No more background processes.

This is certainly caused by the usage of custom fonts. Any custom font I use, the same happens, and without the custom fonts all is working just fine.

How would it be possible to still use my custom fonts and not crash live wallpaper service?

Thank you very much for the responses!

1 Answers1

0

I had a similar problem on a livewallpaper app. I wondered if I add a problem with my opengl textures, finally I have just stated that an app can be cleared from memory at any time if the Android OS needs it and added a recovery process using AlarmManager.

Some references :

https://stackoverflow.com/a/14748123/3540391

https://stackoverflow.com/a/8321512/3540391

Community
  • 1
  • 1
Jacques Giraudel
  • 352
  • 4
  • 19