2

I have the following scenario: -

App loads, an intitial password logon screen appears. Once the user is logged on, they are then taken to a second screen. If they hit the back button on the second screen, I use the following code to take them to the home page of the device: -

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);

The issue is that when I start the app again, it starts from this second screen. I want it to start from the logon screen again.

4

2 回答 2

5

finish()你的第二个活动就在回家之前。

    finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
于 2012-10-18T15:00:09.830 回答
0

为什么不直接调用finish()第二个活动?您不需要通过 callind 将用户重定向到主屏幕startActivity()。如果您的第一个(登录)活动启动了第二个活动并调用finish()了自己,那么您的活动堆栈中只有一个活动(第二个活动)。如果你调用finish()那个,你的活动堆栈中就没有任何东西了,你的应用程序就会结束。

不需要将用户重定向到主屏幕的额外代码。

于 2012-10-18T15:22:02.610 回答