Skip to content Skip to sidebar Skip to footer

Android Sqlite Database Not Working When Returning To Main Activity

I'm working on app that request user to use phone number to login and once they logged in, I'm passing that phone number from LoginActivity to MainActivity via IntentPutExtra evryt

Solution 1:

Tauseef You can get your id, password from LoginActivity to MainActivity like this , First you can store your id and pass in Sharedpreference when you enter your detail id and pass in LoginActivity like as.

        strId = edtEmail.getText().toString().trim();
        strPassword = edtPassword.getText().toString();

        SharedPreferencespreferences= getApplicationContext().getApplicationContext().getSharedPreferences("session", Context.MODE_PRIVATE);
        SharedPreferences.Editoreditor= preferences.edit();
        editor.putString("id", strId);
        editor.putString("pass", strPassword);
        editor.commit();

Second, then you can just get this value in your MainActivity like as.

SharedPreferencespreferences= getApplicationContext().getApplicationContext().getSharedPreferences("session", Context.MODE_PRIVATE);
        StringstrId= preferences.getString("id", "");
        StringstrPass= preferences.getString("pass", "");

        Log.e("Log", "Id---" + strId);
        Log.e("Log", "Pass---" + strPass); 

Solution 2:

Thanks for your support guys. Now my app is working fine as @Secret Coder said i'm using my methods in onRestart() and onPause() and now I'm receiving the Phone Number Entered my user

Post a Comment for "Android Sqlite Database Not Working When Returning To Main Activity"