2

I want to call onCreate(Bundle cicici); from other class then i am getting "NullPointerException", so please guide me how can i call the onCreate() from another class.

Selva
  • 839
  • 10
  • 25
  • 40

3 Answers3

11

There is only one way in which onCreate can be called, by starting an Activity, since onCreate is as part of Activity life cycle.

 startActivity(new Intent(presentActivity.this, NextActivity.class));
Umesh
  • 4,406
  • 2
  • 25
  • 37
  • I want to show my second activity inside first activity.the above intent to show another screen. – Selva Jul 26 '11 at 05:34
  • You want to change the layout? – Rasel Jul 26 '11 at 05:36
  • you cannot have two Activities on top of the stack at the same time. I guess you'll have to redesign your activity to incorporate the information of both activities in a single activity. – Umesh Jul 26 '11 at 05:38
  • Can you call the onStart then? Or is there any way to reload a previously created activity to refresh the contents of it without having to call it again, because that takes time. – Ch. Arham Dec 06 '22 at 13:55
2

if you want to call onCreate in order to actually present a new screen, then you need to create a the new Activity using the android framework style.

Ingredients:

1- An event to call your new activity( ie. onClickListener of a Button or list triggered) 2- On the event you need to create an Intent with the reference of the current activity and a class reference of your new Activity, example:

Intent intent =new Intent(CurrenActivity.this, MyNewActivity.class);

3- You need to call this activity depending on what you'll need you use startActivity or startActivityForResult, the last is use when you expect a response from your activity.

You can also refer to Android documentation Common Task, let us know if its helpful

Necronet
  • 6,704
  • 9
  • 49
  • 89
0

It depends what you want to do in the second activity. If you want to create a simple task you can always use dialogs and you can show them inside your activity. Or, on a second thought, you can hide some of your views and enable others but I guess that's not an orthodox solution :)

Aurelian Cotuna
  • 3,076
  • 3
  • 29
  • 49