0

Note: Please read the full question and if anyone knows the answer or any suggestion feel free to tell me

I am using retrofit 2 for downloading blog data from internet in Json format and show them in a list using recycler view.I set my recyclerview adapter as a retrofit callback.

In my adapter

 //..........
 @Override
public void onResponse(Call<AllBlog> call, Response<AllBlog> response) {
    mPosts = response.body().getPosts();
    notifyDataSetChanged();
}
.....

I create a data model and make them parcelable. In MainActivity.java, I request an api call and when I get some data I saved it on onSaveInstanceState like this

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    //.....
    outState.putParcelable(STATE_BLOG_LIST, value);
    //.....
}

So,In onCreate when onSaveInstanceState is not null I want to pull the data from onSaveInstanceState and set the data in adapter callback in my list adapter.Something like this

if (savedInstanceState == null) {
        showLoading();
        Api.getBlog(mBlogListAdapter);
    } else {
        mBlogListAdapter.onResponse(savedInstanceState.getParcelable(STATE_BLOG_LIST), null);
    }

But when I write that code this mBlogListAdapter.onResponse(savedInstanceState.getParcelable(STATE_BLOG_LIST), null); line of code become red and says Wrong 1st argument type. Found: 'android.os.Parcelable', required: 'retrofit2.Call<io.github.niyamatalmass.treehouseblog.Model.AllBlog>

So I think: I get a parcelable object from savedInstanceState and trying to set that in onResponse method where first paramater is Call<AllBlog> call. So now my question is how I convert the parcelable data to generic type(Call<AllBlog>).

Niyamat Ullah
  • 2,384
  • 1
  • 16
  • 26
  • `Log.d` the value of `savedInstanceState.getParcelable(STATE_BLOG_LIST)`, what do you see on the `logcat`? – pskink Mar 28 '16 at 07:47
  • http://i.stack.imgur.com/ckTau.png When I write the log cat the red line pop up and say "Wrong 2nd argument type. Found: 'android.os.Parcelable', required: 'java.lang.String'" – Niyamat Ullah Mar 28 '16 at 08:46

0 Answers0