I am able to login to skydrive using skydrive API in android. Now i want to use that same session object and liveconnectclient object in another avitivity. How can i do that?
public void onAuthComplete(LiveStatus status, LiveConnectSession session,Object userState)
{
if (status == LiveStatus.CONNECTED)
{
client = new LiveConnectClient(session);
Log.i("message", client.toString());
// StoreSkydriveSession(session);
txtskydrive.setText("Connected");
skydrivefolder.setEnabled(true);
isSkydriveConnected=true;
}
else
{
txtskydrive.setText("Not Connected");
Toast.makeText(getApplicationContext(), "Not Signed In",
Toast.LENGTH_LONG).show();
// this.resultTextView.setText("Not signed in.");
client = null;
}
}
I am able to login .Now how can and where should i store the client and session object so that i can use it in another activites .
I have tried using beans to set and get values but when i try to get it, it throws null pointer exception.
I tried storing it in shared preferences but i cannot cast it from string to LiveConnectClient object.
Thanks :)
EDIT:
I think we can use GSON... Gson (also known as Google Gson) is an open source Java library to serialize and deserialize Java objects to (and from) JSON
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
For save
Editor prefsEditor = mPrefs.edit();
Gson gson = new Gson();
String json = gson.toJson(client); //LiveConnectClient Object
prefsEditor.putString("MyObject", json);
prefsEditor.commit();
For get
Gson gson = new Gson();
String json = mPrefs.getString("MyObject", "");
LiveConnectClient obj = gson.fromJson(json, MyObject.class);
I think this should work....