how to use sharedpreferences in my project android : hey guys how to use sharedpreferences in my project. I have a floating button in my mainactivity and secondactivity when i click the floating button the compass will be disabled then when i go in the secondactivity the compass is enabled which is disabled instead.How to resolve this problem?


here is my code

          FloatingActionButton compass1 = (FloatingActionButton)findViewById(R.id.comp);
        compass1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(findViewById(R.id.relativeLayout1).getVisibility()==View.VISIBLE){
                    findViewById(R.id.relativeLayout1).setVisibility(View.GONE);
                    Toast.makeText(getApplicationContext(),"Compass Has Been Disabled",Toast.LENGTH_SHORT).show();
                }

                else{

                    findViewById(R.id.relativeLayout1).setVisibility(View.VISIBLE);
                    Toast.makeText(getApplicationContext(),"Compass Has Been Enabled",Toast.LENGTH_SHORT).show();
                }
            }

        });