skip to Main Content

what is the use of "notifications" in the underlined part? I had given many different
strings in the place of "notifications" (underlined part) and the code runs without any
issue. So what is the string "notifications" doing here exactly?

Refer to this image down.

https://i.stack.imgur.com/RxZ2p.jpg

2

Answers


  1. It is the name of the sharedpreference value you are assigning. Later when you want to get the value say in another activity you should do something like this

     boolean notificationValue = getSharedPreferences(sharedpreferences, Context.MODE_PRIVATE).getBoolean("notification", true);
    
    Login or Signup to reply.
  2. This is basically an example of a key value pair and it will be coming up again and again in your android development career.

    What a key value pair means is ..

    Imagine a box with a key. Now you put some value in the box and only that particular key ( read value) can open the box.

    So
    sharedpreferences.edit().putBoolean("notifications",false).apply
    creates a box in memory with the key "notifications".

    So when you need to retrieve the value you need to put the key in the appropriate place like

    boolean notificationValue = getSharedPreferences(sharedpreferences, Context.MODE_PRIVATE).getBoolean("notification", true);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search