-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 !

adam
  • 181
  • 2
  • 9
  • 1
    You may want to, for clarity reasons, write a method instead of handling it in the constructor. – zgc7009 Jan 12 '15 at 15:25

2 Answers2

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.

Community
  • 1
  • 1
Raphaël
  • 173
  • 11
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).

Rafal Iwaniak
  • 161
  • 1
  • 12