In connection with a certain architecture, I cannot get an instance of the class in which the variable is initialized. I can declare this variable as static. But are there any other ways?
From this class MainGamePanel extends SurfaceView implements SurfaceHolder.Callback , a stream is created MainThread(getHolder(), this); the variable is initialized in the thread. In the class public class Chronometer , which is not inherited from anything, I cannot get a stream instance, since there is no getHolder (). How to get access to a variable through a static or to use the interface or are there any other more appropriate ways? The variable itself stores time in nanoseconds and changes quite rarely.
public class MainGamePanel extends SurfaceView implements SurfaceHolder.Callback { @Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG,"surfaceCreated"); thread = new MainThread(getHolder(), this); thread.setRunning(true); thread.start(); } } .
class MainThread extends Thread { static int start; } .
public class Chronometer { start = 123; //Какими способами я могу обратиться к этой переменной ,если ее объявить не как статик? Экземпляр класса MainThread создать не могу. }