2

In my manifest I have this:

<activity
  android:name=".BackgroundOptionSlider"
  android:label="@string/update_background" >
</activity>

but my class, BackgroundOptionsSlider, need to have a private default constructor for what I am doing (making sure there is only one instance ever) and for this reason I am getting an error in my manifest's stating that I need to have a public default constructor. How can I get past this?

Daniel Smith
  • 8,460
  • 3
  • 33
  • 58
mr nooby noob
  • 1,571
  • 4
  • 27
  • 51

2 Answers2

3

Since your BackgroundOptionSlider extends an Activity, you can't avoid having a default public constructor.

making sure there is only one instance ever

The way to accomplish this is already given to you by the system, declare

<activity
        android:name=".BackgroundOptionSlider"
        android:label="@string/update_background"
        android:launchMode="singleTask">
    </activity>

OR

<activity
        android:name=".BackgroundOptionSlider"
        android:label="@string/update_background"
        android:launchMode="singleInstance">
    </activity>

More information about the launch mode, and also refer to this question.

Community
  • 1
  • 1
Droidman
  • 10,983
  • 15
  • 91
  • 137
1

You should never try to instantiate the Activity by yourself the android framework does that for you so you should provide a default public constructor,If you want to have only single instance of an activity you can achieve that by specifying the launch mode as singleInstance, here here is a good read about launchModes

nvinayshetty
  • 3,127
  • 1
  • 19
  • 31