0

すべてのアプリケーション データをリセットする方法はありますか? onDestroy()つまり、データベース、キャッシュ、アプリケーション フォルダなどです。アプリケーションが呼び出されたときに実行したいと考えています。グローバルなソリューションを探しています - データベースに作成されたテーブルがわかりません。パッケージ名しかわかりません。

4

1 に答える 1

0

このコードを試してください。

public void clearApplicationData() {
            File cache = getCacheDir();
            File appDir = new File(cache.getParent());
            if(appDir.exists()){
                    String[] children = appDir.list();
                    for(String s : children){
                            if(!s.equals("lib")){
                                    deleteDir(new File(appDir, s));
                                    Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s +" DELETED *******************");
                            }
                    }
            }
    }

    public static boolean deleteDir(File dir) {
        if (dir != null && 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;
                }
            }
        }

        return dir.delete();
    }

礼儀フルピン。詳細については、ここをクリックしてください

于 2013-11-11T08:46:38.817 に答える