Android应用程序退出的主屏幕 [英] Android application Exit for home screen

查看:102
本文介绍了Android应用程序退出的主屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有开发Android应用程序,有我有退出按钮,在菜单中option.I要退出应用程序并进入主屏幕,当我preSS退出按钮。为此,我已经使用 下面的方法

I have develop android application,there I have Exit button in menu option.I want exit application and go to home screen when I press exit button. for that I have used following methods

1。 System.exit(0)

2 完成()

3。 android.os.Process.killProcess(android.os.Process.myPid())

4 System.runFinalizersOnExit(真);

所有这些方法直接应用我的第一页不回家screen.so我应该做这个?请帮我

these all methods direct to application my first page not to home screen.so what should I do for this?? please help me

推荐答案

首先接近一个Android应用程序时,因为背键和home键已经有点给你这个功能皱起了眉头。 但是,如果你需要,你可以做到这一点。

Firstly close in an android application is frowned upon because the back button and home button are already kinda giving you this functionality. But if you need to you can do this

当用户希望退出所有打开的活动,他们应该preSS一个按钮,加载运行你的应用程序启动时的第一个活动。

When the user wishes to exit all open activities, they should press a button which loads the first Activity that runs when your app starts.

    Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("EXIT", true);
    startActivity(intent);

以上code清除除第一个活动的所有活动。然后把这个code里面的第一个活动的的onCreate(),到时候就应该自毁当退出的消息被传递信号

The above code clears all the activities except for first activity. Then put this code inside the first activity's onCreate(), to signal when it should self destruct when the 'Exit' message is passed.

    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();
    }

这篇关于Android应用程序退出的主屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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