「GoogleI/O 2012-少ないコストでより多くのことを行う:優れたAndroidシチズンになる」の講演を聞くhttp://www.youtube.com/watch?v=gbQb1PVjfqM&list=PL4C6BCDE45E05F49E&index=10&feature=plpp_video i apiレベル14以降onTrimMemory
、メモリ使用量の削減などの操作を行う場合はオーバーライドできることがわかりました。しかし、Activityの外、たとえばCursorAdapterにComponentCallbacks2インターフェイスを実装したいと思います。この講演では、次のように述べています。使用しますContext.registerComponentCallbacks()
が、これを使用しようとすると、次のような入力パラメーターが必要になります。mContext.registerComponentCallbacks(ComponentCallbacks callbacks);
どうすればこれを使用できますか?
今私はこれを使用しています
public class ContactItemAdapter extends ResourceCursorAdapter implements ComponentCallbacks2{
... ...
@Override
public void onTrimMemory(int level) {
Log.v(TAG, "onTrimMemory() with level=" + level);
// Memory we can release here will help overall system performance, and
// make us a smaller target as the system looks for memory
if (level >= TRIM_MEMORY_MODERATE) { // 60
// Nearing middle of list of cached background apps; evict our
// entire thumbnail cache
Log.v(TAG, "evicting entire thumbnail cache");
mCache.evictAll();
} else if (level >= TRIM_MEMORY_BACKGROUND) { // 40
// Entering list of cached background apps; evict oldest half of our
// thumbnail cache
Log.v(TAG, "evicting oldest half of thumbnail cache");
mCache.trimToSize(mCache.size() / 2);
}
}
}
しかし、onTrimMemory
呼び出されることはありません。