我试图通过单例模式编写代码。
这是我的主要活动。
public class MainActivity extends AppCompatActivity {
public static MainActivity activity;
public TouchSensor touchSensor;
public SurfaceViewThread surfaceViewThread;
public TriggerChecker triggerChecker;
public Physics physics;
//public static Handler mHandler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
activity = this;
surfaceViewThread = SurfaceViewThread.getInstance();
touchSensor = TouchSensor.getInstance();
triggerChecker = TriggerChecker.getInstance();
physics = Physics.getInstance();
touchSensor.start();
triggerChecker.start();
physics.start();
//surfaceViewThread is already started.
activity.setContentView(surfaceViewThread);
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试通过单例模式编写的代码。
public class SurfaceViewThread extends SurfaceView implements Runnable, SurfaceHolder.Callback {
private static SurfaceViewThread surfaceViewThread = new …Run Code Online (Sandbox Code Playgroud)