之前和onActivityResult后的onCreate称为 [英] onCreate called before and after onActivityResult

查看:123
本文介绍了之前和onActivityResult后的onCreate称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开摄像头以下方式:

I try open camera following way:

...
    private void runCamera() {
        String storageState = Environment.getExternalStorageState();
        if (storageState.equals(Environment.MEDIA_MOUNTED)) {

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File imageFile = new File(Singleton.instanse.mPushFilePath);
            mImageFileUri = Uri.fromFile(imageFile);
            intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                    mImageFileUri);
            startActivityForResult(intent, CAMERA_RESULT);
    }
...

如果我运行此方法运行下一个方法:

if I run this method run next methods:

07-16 19:46:22.264: I/System.out(6875): -onPause
07-16 19:46:26.104: I/System.out(6875): -onStop

我做的照片,运行完下一个方法:

I make photo, end run next methods:

07-16 19:46:41.217: I/System.out(6875): -onDestroy
07-16 19:46:41.284: I/System.out(6875): -onCreate
07-16 19:46:41.291: I/System.out(6875): -onStart
07-16 19:46:41.295: I/System.out(6875): -onActivityResult
07-16 19:46:41.295: I/System.out(6875): -onResume
07-16 19:46:41.295: I/System.out(6875): -onPostResume
07-16 19:46:41.522: I/System.out(6875): -onPause
07-16 19:46:41.522: I/System.out(6875): -onStop
07-16 19:46:41.522: I/System.out(6875): -onDestroy
07-16 19:46:41.604: I/System.out(6875): -onCreate
07-16 19:46:41.612: I/System.out(6875): -onStart
07-16 19:46:41.616: I/System.out(6875): -onResume
07-16 19:46:41.616: I/System.out(6875): -onPostResume

为什么的onDestroy运行twiсe?如何解决呢? 这个问题在Android 2.2的发现。在安卓2.3.3的onDestroy从来没有所谓!

Why onDestroy run twiсe? How to fix it? This problem found in Android 2.2. In Android 2.3.3 onDestroy never called!

推荐答案

其实,相机会导致方向的改变你的活动,这就是为什么你的活动被破坏并重新创建。

Actually the camera causes the orientation change in your activity that is why your activity is being destroyed and recreated.

添加这在你的manifest文件,将prevent的方向变化,你的活动将不会被破坏并重新创建。

Add this in your manifest file it will prevent the orientation change and your activity will not get destroyed and recreated.

<activity
    android:name=".YourActivity"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait" >
</activity>

<一个href="http://stackoverflow.com/questions/10411009/activity-killed-oncreate-called-after-taking-picture-via-intent/10411504#10411504">Activity通过意向拍照

这篇关于之前和onActivityResult后的onCreate称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆