2

我是Android开发的初学者。我的应用程序中有几个屏幕,我可以使用“backstack”功能在这些屏幕之间来回导航。当我深入浏览应用程序时,应用程序的内存使用量正在增加。有时它会达到 100 MB ..!! 它会导致应用程序重新启动。

据我了解,以下可能是内存过度使用的可能原因:

1) 应用大量使用图片。

2) 实现了Backstacking。(只有一次活动使用,其他是片段)

3) 该应用程序有一个持续运行的后台服务。

我不确定这些是否是实际原因。请帮我找出原因。关于内存过度使用问题的任何提示?还有一个问题,Android 应用程序的理想内存使用量应该是多少?

4

1 回答 1

0

在您的应用程序中调用这两种方法,它将从 android 数据中删除所有图像缓存,并且您的应用程序不会因内存问题而崩溃

//this is for clear cache folder in android -> data folder which generate by gallry lazy loading 
        public static void trimCache(Context context) {
            try {
    //         File dir = context.getCacheDir();
               File dir = context.getExternalCacheDir();
               if (dir != null && dir.isDirectory()) {
                  deleteDir(dir);
                  System.out.println("delete cache folderrrrrrrrrr");
               }
            } catch (Exception e) {
               // TODO: handle exception
            }
         }
        public static void trimCacheinternal(Context context) {
            try {
                File dir = context.getCacheDir();
    //          File dir = context.getExternalCacheDir();
                if (dir != null && dir.isDirectory()) {
                    deleteDir(dir);
                    System.out.println("delete cache folderrrrrrrrrr");
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
于 2014-02-27T07:26:28.473 回答