Selva
Selva

Reputation: 839

How to call onCreate method from other class?

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.

Upvotes: 2

Views: 18748

Answers (3)

Necronet
Necronet

Reputation: 6813

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

Upvotes: 2

Aurelian Cotuna
Aurelian Cotuna

Reputation: 3081

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 :)

Upvotes: 0

Umesh
Umesh

Reputation: 4256

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));

Upvotes: 11

Related Questions