Galaxy S3 - taking picture in portrait mode destroys activity

前端 未结 2 2091
傲寒
傲寒 2020-12-31 05:53

So, this question has been asked in many forms on this forum but none of the answers are helping me. I have a bug which I\'ve only been able to reproduce on the Samsung Gal

相关标签:
2条回答
  • 2020-12-31 06:00

    Android can call the destroy() method in certain scenarios. One is when we use the method finish(). An alternative is to use the method isFinishing () from Activity class. If it really is being finalized could finalize their resources, otherwise, you can keep the values ​​allocated a class that inherits Application

    @Override
    protected void onDestroy() {
    
        final YourApp app = (YourApp) getApplicationContext();
        if (app != null && isFinishing()) {
            app.finalizeAppResources();
        }
    
        // ...
    
        super.onDestroy();
    }
    
    0 讨论(0)
  • 2020-12-31 06:04

    If you are targeting beyond API level 13, Adding

    android:configChanges="orientation|keyboardHidden"
    

    to the Manifest will not be enough.

    Check this extract from Android documentation

    Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.

    Hence try adding

    android:configChanges="orientation|keyboardHidden|screenSize"
    

    to your Manifest file. This should solve your problem.

    0 讨论(0)
提交回复
热议问题