I’m trying to call MainActivity.my_method()
from a different class, but I get:
non-static method my_method(Context) cannot be referenced from a static context.
MainActivity.java
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
my_method(); //WORKS WELL
}
public void my_method(Context context) {
context.startActivity( new Intent( Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse( "package:" + context.getPackageName() ) ) );
}
}
My_view.java
class My_view extends SurfaceView implements SurfaceHolder.Callback {
class My_viewThread extends Thread implements SensorEventListener, OnTouchListener{
…
private Context mContext;
…
public void my_calling_method() {
MainActivity.my_method(mContext);
}
....
Any help will be very appreciated.