简体   繁体   English

Android-活动在调用startActivity之后仍然被销毁

[英]Android - Activity persist as destroyed after call startActivity

This is the problem´s cenary: 这是问题的场景:

The Activity "A" have a button than call startActivity B. 活动“ A”具有一个按钮,而不是调用startActivityB。

The Activity "B" have a button then call finish(). 活动“ B”有一个按钮,然后调用finish()。 So the app show Activity "A" again. 因此,应用再次显示活动“ A”。

Now, If i call activity "B" the property mDestroyed = true 现在,如果我将活动称为“ B”,则属性mDestroyed = true

The problem: When i access B a second time B is destroyed 问题: 当我第二次访问B时,B被破坏了

Why B continue destroyed after i call startActivity? 为什么在我调用startActivity之后B继续被破坏?

Someone can help me? 有人可以帮我吗?

ManifestFile: 清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.xxxxxx">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="xxx"
        android:supportsRtl="false"
        android:theme="@style/MyMaterialTheme">

        <activity
            android:name=".BaseActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".A"
            android:screenOrientation="portrait" />
        <activity
            android:name=".B"
            android:screenOrientation="portrait" />

    </application>

</manifest>

Activity B method: 活动B的方法:

 @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }

Activity A method: 活动A方法:

   @Override
                    public void onClick(View view) {
                        startActivity(new Intent(MainActivity.this, B.class));
                    }

When i acess B a second time: 当我第二次访问B时: 当我第二次B

finish() method calls onDestroy() of activity . finish()方法调用activity的onDestroy() Replace finish() with finish()替换为

startActivity(new Intenet(CurrentActivity.this, NewActivity.class));

Your current activity will be in background. 您当前的活动将在后台进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM