Android - 再次使用singletask调用活动会在android l上产生黑屏

时间:2016-04-15 06:56:18

标签: android

我有MainAcitvity(Singletask)SecondActivityForwardActivity

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(intent);
            }
        });
    }
}

这是SecondActivity

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_task_acitvity);
        findViewById(R.id.bt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SecondActivity.this, ForwardActivity.class);
                startActivity(intent);
            }
        });
    }
}

这是ForwardActivity

public class ForwardActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forward);
        Intent intent = new Intent(ForwardActivity.this, MainActivity.class);
        startActivity(intent);
    }
}

在Android 5.0+上,这会导致黑屏。

如果我使用windowIsTranslucent添加SecondAcitvity,则会出现黑屏问题。

如何在不添加windowIsTranslucent的情况下解决黑屏问题?

谢谢你。

0 个答案:

没有答案