将主屏幕编程 [英] Going to home screen programmatically

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

问题描述

我要到主屏幕编程Android中,当用户点击按钮。如何才能做到这一点?

I want to go to the home screen programmatically in Android when the user clicks on button. How can this be done?

推荐答案

您可以通过意向做

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

此意图将启动用户定义的启动应用程序。小心这一点,因为这会看起来像你的应用程序崩溃,如果用户不希望这一点。

This Intent will start the launcher application that the user has defined. Be careful with this because this will look like your application crashed if the user does not expect this.

如果你想这从你的应用程序建立一个退出按钮,请阅读这篇文章上的退出按钮的Andr​​oid中

If you want this to build an exit button from your app please read this article on exit Buttons in Android

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

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