SUPLMMM
SUPLMMM

Reputation: 13

Call Public void

I have a public void in one class and I want to call it in another class when it creates but nothing seems to be working. here is the code of my first activity

public class activityone extends Activity {

public void actionC() {

//actions

}

Does anyone know how to call it in my second class?

Upvotes: 0

Views: 7830

Answers (2)

GAMA
GAMA

Reputation: 5996

Here is what you can do:

public class activityone extends Activity {

/*public void actionC() {*/ //Instead on normal method, write your actions in onCreate()

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//actions
}

and in your second activity, do this:

Intent intent = new Intent(getApplicationContext(),activityone.class);
startActivity(intent);

Hope it helps !!!

Upvotes: 0

brianestey
brianestey

Reputation: 8302

In general, you need to have an instance of your activityone class in order to call an instance method.

To create an instance, you generally use a constructor like:

activityone a = new activityone();
a.actionC();

I'm not sure this is what you want though, because Activitys are generally created by the Android system itself and you should handle the onCreate method instead.

Upvotes: 1

Related Questions