2

I have used fragments to communicate with a Fragment Activity, and this Fragment Activity passes its reference to handle the click events in the Fragment as below.

 Bundle tempBundle = new Bundle();
tempBundle.putParcelable("Interface", (Parcelable) new ClickHandler());

Where

class ClickHandler implements ItemClickListener, Parcelable
{
 }

This works perfectly fine, while i Browse through the application, the problem is caused, only when i exit the Application(by pressing the HOME key) and after few minutes when i return Back to the application from Recently used applications(mind that coming back to the application immediately wont cause an exception).

does any one has ever faced such issues

Anuj
  • 2,065
  • 22
  • 23

1 Answers1

0

I also had this problem and it took me quite a lot of time to figure out where the error is occurring. What I did is to follow the advice in the accepted answer of this question.

The first step I did is to hunt down instances where the app is recovering data from a savedInstanceState related to the class where the crash occurs. I simply set the class loader of those savedInstanceState bundles, as recommended in the link I have provided. It did not work the first time though. The crash still occurs, but it has changed its error log stack trace such that no line in my code is being pointed out. And then I looked for possible null values in my custom parcelable objects, and set them to non null values. This might be a pain to do especially if you are checking for null in some places in your code. You just have to clench your teeth and do it because apparently, Android does not like null values in parcelables.

After doing those two, it still does not work for me. So I looked even further and I noticed that I'm actually restoring instances from a bundle in an adapter. Some adapters do that, for instance, FragmentStatePagerAdapter. I simply set the classloader of that bundle and then it worked out for me.

Community
  • 1
  • 1
avendael
  • 2,459
  • 5
  • 26
  • 30