-1
  1. In my application am getting Facebook information by using Facebook SDK and data stored in

variables then its working fine.But if am restart the mobile all variables are shows null(in log-cat)

and Application not working properly.

  1. I am passing data to server like this

     HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
    
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("firstname",firstname));
            nameValuePairs.add(new BasicNameValuePair("lastname", lastname));
    
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
            HttpResponse response = httpclient.execute(httppost);
    

it gives response like this

{
      "message": "Successful",
    "data": {
        "user_id": 32,
        "firstname": "myname",
        "lastname": "lastname"
    }
 }

how can i get the user_id from above response or any other way. Please tell me how can i solve these issues.Thanks in advance

2 Answers2

1

Store your values in Preferences or SQLite Database.

Preferences

android-preferences-tutorial

Android SQLite

Android SQLite Database

M D
  • 47,665
  • 9
  • 93
  • 114
0

Hi,use SharedPreferences to store data and you can access through out the app.

start with initialize prefs in your Class constructor

SharedPreferences prefs = context.getSharedPreferences("com.namespace.pkg",
                        Context.MODE_PRIVATE);

and use two functions getPrefs() to get and setPrefs() to set values in sharedPreferences

                public String getPrefs(String name) {
                    return prefs.getString(name, "");
                }

                public void setPrefs(String key, String value) {
                    prefs.edit().putString(key, value).commit();
                }
J.K
  • 2,290
  • 1
  • 18
  • 29