-1

this is my public class in android!

public class Logout {
public SharedPreferences pref;
public Logout(Context context){
      pref = context.getSharedPreferences(LoginActivity.loginpreferences, context.MODE_PRIVATE);
      SharedPreferences.Editor editor = pref.edit();
      editor.remove(LoginActivity.name_user);
      editor.remove(LoginActivity.type_user);
      editor.remove(LoginActivity.id_user);
      editor.commit();
 }
}

to call class when clicking button (logout) I wrote the code in the following way

    private OnClickListener clickitempanel = new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        int id = v.getId();
        switch(id){
        case 4:
               Logout logout = new Logout(mContext);
             //  logout.notifyAll();
               logout.getClass();
               Intent in = new Intent();
               in.setClass(mContext, FullscreenActivity.class);
               mContext.startActivity(in);
               break;

        }


    }
};

  textViewItem.setOnClickListener(clickitempanel);

but doesn't running code remove keys from SharedPreferences !

1
  • 1
    You may want to, for clarity reasons, write a method instead of handling it in the constructor. Commented Jan 12, 2015 at 15:25

2 Answers 2

0

Do you have a listener on that button? Are you sure it is working ?

Also, you people would normally put that logout code in a method instead of in the constructor.

Sign up to request clarification or add additional context in comments.

Comments

0

Hint:

Remember to make as less as it is is possible in body of Constructor. Init your variables and avoid call any methods. Only methods which you could call in Constructor are final methods (private method also should be with final statement).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.