【问题标题】:Can I delete SD card data specific to an application at uninstall?我可以在卸载时删除特定于应用程序的 SD 卡数据吗?
【发布时间】:2012-08-23 13:50:38
【问题描述】:

我可以在以编程方式卸载应用程序时删除特定于应用程序的 SD 卡数据吗?

【问题讨论】:

标签: android


【解决方案1】:

使用这个

@Override
    protected void onDestroy()
    {
        super.onDestroy();
        File checkFile = new File("/sdcard/Accentra/");//getting the control of sdcard files
        deleteDir(checkFile);
    }

    //Deleting the temperary folder and the file created in the sdcard
    public static boolean deleteDir(File dir) 
    {
        if (dir.isDirectory()) 
        {
            String[] children = dir.list();
            for (int i=0; i<children.length; i++) 
            {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) 
                {
                    return false;
                }
            }
        }
        // The directory is now empty so delete it
        return dir.delete();
    }

【讨论】:

  • 我的应用程序中确实有几个活动,我必须编写哪个活动来编写 onDestroy() 方法?
猜你喜欢
  • 2012-08-04
  • 1970-01-01
  • 2011-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
  • 2019-12-02
相关资源
最近更新 更多