0

I want to know if there is a way to pass all the extras to the new intent.

Is it possible? And is it a good idea?

The reason is that I want to save the login state as a json string, and pass it in between Activities. I don't want to store data with SQLite or anything. Can I bypass all the intent extras to the new intent ?

ThatBlairGuy
  • 2,426
  • 1
  • 19
  • 33
mobilGelistirici
  • 449
  • 4
  • 7
  • 19

3 Answers3

2

please consider Shared Preference :

  // Declaration
   public static String KEY = "SESSION";

   public static void saveUserName(String username, Context context) {
        Editor editor = context
                .getSharedPreferences(KEY, Activity.MODE_PRIVATE).edit();
        editor.putString("username", username);
        editor.commit();
    }

    public static String getUserName(Context context) {
        SharedPreferences savedSession = context.getSharedPreferences(KEY,
                Activity.MODE_PRIVATE);
        return savedSession.getString("username", "");
    }

You can store the login credentials to preference and retrieve them as well in any of your activity.

SaveUsername("Your text to save", Your_activity.this);

And to retrieve the value

String mUserName = getUserName(YourActivity.this);

It is recommended to have all your preference methods in your utils class to keep the code organized.

You can read more here

Rethinavel
  • 3,912
  • 7
  • 28
  • 49
  • Thanks! This looks like exactly what I need. and one question: when does this session get deleted? When the application is closed ? or, sleep? or uninstall? – mobilGelistirici Nov 06 '13 at 12:11
  • Case 1 :When you click Settings --> Application --> Manage application --> Your Application --> Clear Data Case 2 : Unistall the app. The preference values remains even if you exit from the application. – Rethinavel Nov 06 '13 at 12:14
0

yes you can use Shared Preference to save the Login session of user here is handy example of managing session using shared preference http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/ I used it earlier and suggest you to have a look at it.

Nitin Misra
  • 4,472
  • 3
  • 34
  • 52
0

Any of the two may help you.

  1. Saving it in the sharedPreference file.
  2. If you want them to be accessable throught the application you can use the applicationClass, like a global singleton.
Community
  • 1
  • 1
amalBit
  • 12,041
  • 6
  • 77
  • 94