0

I am calling a class's member function from another class. So,I am creating an object of the class for which i have to call constructor. Within that constructor, I need to call onc reate method of my activity class.how can I do it?

3 Answers3

5

Do not call onCreate from your constructor. The system itself will call onCreate for you.

Take a look at the Activity Lifecycle for more information of how onCreate is called.

brianestey
  • 8,202
  • 5
  • 33
  • 48
0

All method's of Activity class should be called within activity only . write your own methods for whatever operation you need to perform and pass data from other Activity/class by various data transfer algorithms .

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
  • Thanks for the info. But, still i am getting error in my constructor. public myactivity(Bundle savedInstanceState) { Log.v("myactivity", "Inside myactivity Constructor"); db = (new DatabaseHelper(this)).getWritableDatabase(); if (db == null) Log.v("myactivity", "DB Creation Failed"); } Can u please help me? – androiddeveloper Dec 07 '11 at 09:25
  • nobody can . until you post code with errorLog . so please do it – Shailendra Singh Rajawat Dec 07 '11 at 10:03
  • Thanks Shailndra, finally got it. Created anew project & implemented on create method instead of going for constructor. – androiddeveloper Dec 07 '11 at 13:35
0

Well,i presume u r trying to call a constructor in an activity.If that is the case then some thing is wrong in the way u have designed ur project.For more details check out these links Creating an object of Android Activity class and Android - Activity Constructor vs onCreate

Community
  • 1
  • 1
androidGuy
  • 5,553
  • 12
  • 39
  • 56