Singleton Pattern+Activity?

Put your problem here if it does not fit any of the other categories.

Singleton Pattern+Activity?

Postby bavarol » Fri Jul 25, 2008 8:00 am

Hi all,
can I develop an activity as singleton class?

In google, they say, it's allowed but I get an "IllegalAccessException" exception

"An Error has occurred in process com.google.android.tour_guide. Unable
to instantiate activity ComponentInfo{name_of_package/name_of_package.name_of_activity}:
java.lang.IllegalAccessException: access to constructor not allowed"

If it's possible, what do I need?

public class Activity1 extends Activity {

private static Activity1 myInstance
private Activity1() {
//
}


public static synchronized Activity1 getInstance() {

if (myInstance == null) {
myInstance = new Activity1();
}
return myInstance;
}
}

It should be instantiated in other class like this:
Activity1 act = Activity1.getInstance();

What am I doing wrong?

Thx in advance
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 30 guests