Alexander
Alexander

Reputation: 35

Starting activity after creating it

I work with interfaces, thus before starting certain activity I create it, assign pointer to the public property of the activity to start (I want to run some function from activity to start and the implementation of course in starting activity) The code

ActivityToStart act = new ActivityToStart ();   
act.delegate = (MyInterface) StartingActivity.this;
Intent i = new Intent(StartingActivity.this,ActivityToStart.class);
act.startActivity(i);

StartingActivity implements MyInterface.

I get an error, unfortunately not informative (null pointer exception)

Why?

Upvotes: 0

Views: 36

Answers (1)

matiash
matiash

Reputation: 55350

Activity classes cannot be directly instantiated.

You must do so via startActivity(), with Intents. To send information, you can add "extras" to the Intent, then read them in the second activity's onCreate() method.

See Starting Another Activity in the documentation.

Upvotes: 1

Related Questions