In one class I call a function from another class which is on another .java file.
This is the function
public void make_a_call(String phonenumber) {
Intent phone_call = new Intent(android.content.Intent.ACTION_CALL, Uri.parse("tel:"+phonenumber));
startActivity(phone_call);
}
The problem is this function requires it to be non static because of startActivity, but when I call this function from another class, it says that, to call it, this function needs to be static.
How can I fix this?
thanks.
The other class needs a reference to a context that will be used to start the activity. One solution is to pass a reference to the activity (the one that contains
make_a_call) to the code in the other class. Another possibility (if the other class is a custom view, for instance), is for it to usegetContext()to obtain a context and then modifymake_a_callto bestaticbut to accept a context as an argument: