I was trying to make simple openGL ES application(currently learning), when I lock the phone or clicking to return button, onStop triggering itself and when i unlock or open the app from tasks, the activity re-creating itself and the triangle(from android studio opengl es beginner documents) corrupting.
I have tried to log when app triggers onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.w("ONCREATE", "Hello, something happened here.");
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
mSurface = new SurfaceView(this);
setContentView(mSurface);
}
I want my application to not re-create the activity(I want it to create when actually starts, no more).
Thanks.
No, you cannot prevent an Activity from being recreated when the screen turns off or the user homes out.
I recommend you start your journey through Android via the official Android Fundamentals to understand the lifecycle of an Android application in the constrained environment of a Linux OS running on a constrained device (your Phone/Tablet).
You should stop rendering/release your OpenGL surfaces when the activity/application is stopped, to stop using user resources and recreate it once you get back.