简体   繁体   English

Android无法以编程方式启动启动器活动

[英]Android can't start launcher activity programmatically

I want to implement such scheme: if in activity's onCreate i catch exception -> start launcher activity. 我想实现这样的方案:如果在活动的onCreate我捕获到异常->启动启动器活动。 I tried to do this in dif ways: 我试图以不同的方式做到这一点:

Intent intent = new Intent(this, StartActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction(Intent.ACTION_MAIN);
startActivity(intent);

and

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

but my app only closes. 但我的应用程序仅关闭。 What is wrong? 怎么了?

Thanks to @Ersin Gülbahar : 感谢@ErsinGülbahar:

Intent startMain = new Intent(this, StartActivity.class);
startActivity(startMain);

So simple. 很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM