Question

There is an activity which should not exist when a user leaves it. That's why it has finish() method in the onStop.

@Override
protected void onStop() {
    super.onStop();
    finish();
}

However, this makes it restart each time the screen orientation changes. At the moment I handle this via Manifest Activity tag android:configChanges="orientation" and overriding method onConfigurationChanged

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.someactivity);
    doAllInitializations();;
}

Is there a better way to handle such situations?

Était-ce utile?

La solution

You can stop this orientation by adding android:configChanges="orientation|keyboardHidden" in your activity tag in the manifest file.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top