Search code examples
androidcordovamobile-application

Detecting first use of a mobile application


I want to write a mobile application(android) using Phonegap and I want to detect first use of my application in order to perform some activation process. How can I detect is this a first use of my application or not? Should I use any database?or something like cookies?


Solution

  • You write this function to anywhere :

    public static String LoadPreferencesString(Context con, String key) {
        // ContextWrapper wrapper=new ContextWrapper(con);
        SharedPreferences sharedPreferences = con.getSharedPreferences(
                "yourxmlfilename", Context.MODE_PRIVATE);
        String strSavedMem1 = sharedPreferences.getString(key, "");
        return strSavedMem1;
    }
    
    public static void SavePreferencesString(Context con, String key, String value) {
        SharedPreferences sharedPreferences = con.getSharedPreferences(
                "yourxmlfilename", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.commit();
    }
    

    You can write a value with key to xml file which youidentified name at first run time. The other you check the value is null. If value is null(or space( )) the app is running first time.