-1

I'm using the twitter API for android. From a call, a List of 'Tweet' objects is returned. I want to save this list into my savedInstanceBundle when required so I don't have to make the large http call again. The problem is that 'Tweet' does not implement parceable or serializable so I cant input it into the bundle.

What are my options?

Call<List<Tweet>> lookup = apiclient.getStatusesService().lookup(ids, true, false, false);

lookup.enqueue(new Callback<List<Tweet>>() {
        @Override
        public void success(Result<List<Tweet>> result) {
            Response response = result.response;
            List<Tweet> tweets = result.data; //what I'd like to save
        }
SimpleJack
  • 151
  • 1
  • 12
  • Post of your code of getting Tweet objects?how do you hold those objects without having Tweet class? – Man Jul 12 '18 at 18:40
  • The API returns a List of 'Call' items given a bunch of twitter post IDs. You can then make an http request for each 'Call'. The result of the call, given in a callback, is a List of 'Tweet' objects – SimpleJack Jul 12 '18 at 22:11

2 Answers2

2

You can not do this its mentioned in doc also . Object should be Marshal before passing for that you can use Serializable or parcelable.

The other way you can use an data-interchange format like JSON or XML or any other . But this way it will much more to write for marshal and unmarshal. So you better make use of Bundle.putParcelable/Bundle.getParcelable or Bundle.putSerializable/Bundle.getSerializable .

It also depends on where exactly you passing the Object . You should look at Be Careful Where You Use Custom Parcelables . One of the Scholar Commansware's blog.

If you need to pass object beetween component when application in foreground then Parcelables is the best way .

ADM
  • 20,406
  • 11
  • 52
  • 83
1

You can't. All you can do is take the information from it, create your own object that is Parcelable or Serializable, and send that.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127