0

Following is the response that i get for a succesfull login. If i logout the token here would change. What I want here is i want to pass token id to another page which has a different url. And each time the token id changes il have to change the token id in the url. How do i do this?? Please Help!!

{
    "status": {
    "message": "    ",
    "Code": 200
    },
    "Error_Code": 0,
    "Error_Message ": "",
    "Token": "vqcrk5wp8646th",
    "User Details": {
    "user_reg_id": "123",
    "Name": "ABC",
    }
faranjit
  • 1,567
  • 1
  • 15
  • 22
bythestarz
  • 29
  • 1
  • 10
  • You should save the token in the SharedPreference – Chol Aug 02 '16 at 08:36
  • 2
    Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – faranjit Aug 02 '16 at 08:43

2 Answers2

0

Create a static constant class to store the token id it can be override when you want to.here how to use assign and use it in any where in application.

Class Constant{
public static String token_id=null;

}

And set your token after parsing

String token_id=json.getString("token");
Constant.token_id=token_id;

And Retrieve it when bind to url

String existing_token_id=Constant.token_id;

OR You can use shared preference to store token id

Use of SharedPreference

And set your token after parsing

String token_id=json.getString("token");
SharedPreference  pref= PreferenceManager.getDefaultSharedPreferences(Activity.this);

SharedPreferences.Editor editor = pref.edit();
            editor.putString("token_id", token_id);
            editor.commit();

And Retrieve it when bind to url

SharedPreference  pref= PreferenceManager.getDefaultSharedPreferences(Activity.this);

String existing_token_id=pref.getString("token_id",null);

Hope this will help you.let me know.

Andolasoft Inc
  • 1,296
  • 1
  • 7
  • 16
0

use this hope solve your problem

SharedPreferences preferences;
String MYPREF="dataRecord";
 SharedPreferences.Editor editor;

preferences=getSharePreferences();

editor=preferences.edit();
//save your session key here
editor.putString("user_reg_id","123");
editor.commit();
Manish
  • 234
  • 2
  • 13