Implement localStorage.clear on Android

This commit is contained in:
pandamicro 2015-05-14 10:40:25 +08:00
parent 3190d0e5fb
commit 8577055d5a
2 changed files with 21 additions and 0 deletions

View File

@ -101,6 +101,15 @@ public class Cocos2dxLocalStorage {
}
}
public static void clear() {
try {
String sql = "delete from "+TABLE_NAME;
mDatabase.execSQL(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This creates/opens the database.

View File

@ -147,4 +147,16 @@ void localStorageRemoveItem( const std::string& key )
}
/** removes all items from the LS */
void localStorageClear()
{
assert( _initialized );
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "clear", "()V")) {
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}
#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)