java - How to store LiveConnectClient and session object of Skydrive API in sharedpreferences -


i able login skydrive using skydrive api in android. want use same session object , liveconnectclient object in avitivity. how can 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 able login .now how can , should store client , session object can use in activites .

i have tried using beans set , values when try it, throws null pointer exception.

i tried storing in shared preferences cannot cast string liveconnectclient object.

thanks :)

edit:

i think can use gson... gson (also known google gson) open source java library serialize , deserialize java objects (and from) json

sharedpreferences mprefs = getpreferences(mode_private);  save   editor prefseditor = mprefs.edit();  gson gson = new gson();  string json = gson.tojson(client); //liveconnectclient object  prefseditor.putstring("myobject", json);  prefseditor.commit();  gson gson = new gson(); string json = mprefs.getstring("myobject", ""); liveconnectclient obj = gson.fromjson(json, myobject.class); 

i think should work....

if need access same objects in different activities easiest way - create kind of handler class:

class liveconnectclienthandler{  public static liveconnectclient client;  } 

then when got it:

public void onauthcomplete(livestatus status, liveconnectsession session,object userstate) { if (status == livestatus.connected) { liveconnectclienthandler.client = new liveconnectclient(session); 

so in other activity may - liveconnectclienthandler.client.

but not sure right way.

first of sending data 1 activity should put in intent.

in second may have other way liveconnectsession object? because can shell simple string resources access_token.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -