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,561
  • 3
  • 35
  • 58
mr nooby noob
  • 1,860
  • 5
  • 33
  • 56

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
  • 11,485
  • 17
  • 93
  • 141
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,187
  • 1
  • 21
  • 32