Vinz
Vinz

Reputation: 45

How to lock levels in Android app

I am developing a quiz application in Android. In my application I'm having categories and I added levels in each category. Now I need to lock all the categories except the first one. The user will be able to unlock the Categories only after he/she completes the specific goal of the level. I don't know how to lock categories in Android. Categories are in the form of buttons. By using the following I'm populating the list and passing of three categories, i.e. Hollywood, Bollywood and Music.

hollywood = (Button) findViewById(R.id.main_hollywood);
    Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
            "Font/game_font.ttf");
    hollywood.setTypeface(tf);
    OnClickListener listener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            settings.edit().putBoolean("check", false).commit();
            Intent intent = new Intent(getContext(), SceneActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(intent);
            finish();
        }
    };
    hollywood.setOnClickListener(listener);


    bollywood = (Button) findViewById(R.id.main_bollywood);
    tf = Typeface.createFromAsset(getContext().getAssets(),
            "Font/game_font.ttf");
    bollywood.setTypeface(tf);
    listener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            settings.edit().putBoolean("check", false).commit();
            Intent intent = new Intent(getContext(), SceneActivity1.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(intent);
            finish();
        }
    };
    bollywood.setOnClickListener(listener);
    music = (Button) findViewById(R.id.main_music);
    tf = Typeface.createFromAsset(getContext().getAssets(),
            "Font/game_font.ttf");
    music.setTypeface(tf);
    listener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            settings.edit().putBoolean("check", false).commit();
            Intent intent = new Intent(getContext(), SceneActivity2.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(intent);
            finish();
        }
    };
    music.setOnClickListener(listener);


}

Upvotes: 0

Views: 1131

Answers (1)

Vinay Jayaram
Vinay Jayaram

Reputation: 1005

There are two methods to solve this

  1. Use shared preference in your application where you can handle the situation onlick

  2. Use sqlite database and update the column appropriately

Let me know if you need further information

For shared preference you can use TinyDb

This class simplifies calls to SharedPreferences in a line of code. It can also do more like: saving a list of strings, integers and saving images. All in 1 line of code!

Example usage:

    TinyDB tinydb = new TinyDB(context);

    tinydb.putInt("clickCount", 2);
    tinydb.putFloat("xPoint", 3.6f);
     tinydb.putLong("userCount", 39832L);

    tinydb.putString("userName", "john");
    tinydb.putBoolean("isUserMale", true); 

    tinydb.putList("MyUsers", mUsersArray);
    tinydb.putImagePNG("DropBox/WorkImages", "MeAtlunch.png", lunchBitmap);

//These plus the corresponding get methods are all included This is just an example of how easy it is to use. There are many more usefull methods included in the class. Enjoy :)

Upvotes: 1

Related Questions