0

I have a Fragment named Fragment_scheduled_newdetail and following is a constructor I am passing to this Fragment when launching, I get the following error:

Error:Error: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead [ValidFragment]

This seems to happen in Android Studio only (I am porting this project from Eclipse, no issue in Eclipse)

When I try to create a app in release mode

public Fragment_scheduled_newdetail(BlockInfo blockToDisplayT) {
    super();
    this.blockToDisplay = blockToDisplay;
}

enter image description here

If I generate the APK in debug mode, it works fine. (release mode will fail) enter image description here

2

2 Answers 2

2

I know the answer is already accepted, but for others who finding the most easiest way to avoid this . So just try this, it helps me out :

android {
    lintOptions {
        checkReleaseBuilds false
    }
}

Just write this n your build.gradle file, then sync the project and try making again signed apk.

1

This is a good strong suggestion by Android Studio. The reason is "constructors will not be called when the fragment is re-instantiated". Instead setArguments(Bundle) will. This is according to Google webpage @ Fragment. Do you have code for Bundle passing?

In Android framework, override methods like onCreate and onCreateView are reinstated, not constructors, like when user changes orientation.

3
  • ok, yea trying to figure that out now ... passing bundle between Fragments. Will mark this as answer once i get it working Jun 4, 2015 at 8:34
  • @user1406716, I added a comment in my post. It says "In Android framework, override methods like onCreate and onCreateView are reinstated, not constructors, like when user changes orientation" Jun 4, 2015 at 8:49
  • @user1406716, How are you doing now with passing Bundles? Jun 4, 2015 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.