Showing posts with label SharedPreferences. Show all posts
Showing posts with label SharedPreferences. Show all posts

Saturday, September 19, 2015

Save value for later use using shared preferences

//1. setting up sharedPreferences for signoutstate
            SharedPreferences explicitSignOut = getSharedPreferences("madtrain", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = explicitSignOut.edit();
            editor.putInt("explicitsignout", signout);
            editor.commit();

Tuesday, September 15, 2015

SharedPrefences Problem

SharedPreferences cannot be called from outside onCreate()
public class MainActivity extends Activity implements
        SoundPool.OnLoadCompleteListener,
        View.OnClickListener,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener
{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.activity_main);


        SharedPreferences loginState =getSharedPreferences("loginState", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = loginState.edit();

..
..
} //END ONCREATE


    @Override
    public void onConnected(Bundle connectionHint) {
        // The player is signed in. Hide the sign-in button and allow the
        // player to proceed.

HERE WE WANT TO COMMIT

    } 
} // END MAIN ACTIVITY