将主屏幕编程屏幕

2023-09-11 12:43:57 作者:σκ吣凊-蚚朌

我要到主屏幕编程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