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

user1406716
  • 9,565
  • 22
  • 96
  • 151
  • see this link http://stackoverflow.com/questions/12062946/why-do-i-want-to-avoid-non-default-constructors-in-fragments – N J Jun 04 '15 at 08:14
  • I would take the suggestion by Android Studio, forget the universal Eclipse (how could they know?). I'll post an answer for you. – The Original Android Jun 04 '15 at 08:18

2 Answers2

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.

Pihu
  • 1,041
  • 11
  • 35
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.

The Original Android
  • 6,147
  • 3
  • 26
  • 31