I am making an app in which I have two switch button,one for twitter login and other for twitter login.
I have gone through other posts on the same topics ( first, second)
but nothing is helping me,that's why posting a new question.
So basically am having a switch button to login and logout. It's working perfectly fine. If I close the app and again return back to the app, that too is working fine i.e session is kept intact but the status button is set to false i.e inactive.
I followed other answers and if I implement that, I get an error that Caused by: java.lang.IllegalArgumentException: Callback must not be null.
(for twitter login).
I'll post some code's,to explain the situation.
tSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked){
SharedPreferences.Editor editor = getSharedPreferences("com.example.anubhaw.socialtwitter", MODE_PRIVATE).edit();
editor.putBoolean("service_status", tSwitch.isChecked());
editor.commit();
loginButton.performClick();
}else{
Twitter.getInstance();
Twitter.logOut();
twitter_layout.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), "Logged out from Twitter", Toast.LENGTH_SHORT).show();
}
}
});
SharedPreferences prefs = getSharedPreferences("com.example.anubhaw.socialtwitter", MODE_PRIVATE);
boolean tState = prefs.getBoolean("service_status", false);
if(tState){
//Do your work for service is selected on
Toast.makeText(getApplicationContext(), "Inside the sharedPref", Toast.LENGTH_SHORT).show();
tSwitch.setChecked(true);
} else {
//Code for service off
}
If I remove the sharedPref thing,everything is working fine,other than the state of that switch button.
Please let me know if you need any more info. Thanks