0

What is the best way to load a class within the onCreate statement of an activity? I have two classes, one (titled second) is to be "loaded" when the main activity begins. Hopefully my example code will better explain what I'm trying to say:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.somelayout);
    <some class here>;
}

I have been trying a few things, one for example is: Date.class.cast(null);

Any suggestions would be appreciated.

Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
MADPADGE
  • 113
  • 2
  • 12

2 Answers2

3

I'm not entirely certain of what you're trying to do, but what you've kinda described is instantiating a class. You can do that like this:

MyClass instance = new MyClass();
Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
0

To load a class you just have to use it. If all you want is a reference to the class you can use

Class myClass = MyClass.class;
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130