简体   繁体   中英

How can I store object into Shared-Pref or Database : Android?

I am doing an sample application, where I want to tweet some updates to Twitter. I am using SocialLib to do this.

Problem description:

twitter = SocialNetworkHelper.createTwitterConnector(CONS_KEY, CONS_SEC, CALLBACK); 

After executing above code, I need to store twitter (an object of TwitterConnector) into persistent storage. Reason is that I don't need user interaction after first time when user authorizes the app.

I can store this object into Application class, and I did it also. But when my application goes into the background, Application class data goes to destroy and I am unable to send tweets from the background state of my application.

I used GSON to change object into string and store into SharedPrefrences but its not working.

Question :

  • How can I store the object of TwitterConnector in persistence storage?
  • Or is there any way to send tweets from the background state of my application, without user interaction?

It may be impossible to store TwitterConnectorat all, or it may need some initialisation after deserialisation. Nobody can tell you more unless you provide link to source of this twitter connector.

As twitter is just a REST service, it is possible to send messages from background seervice without additional user authorisation - once 0Auth credentials were properly set up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM