【发布时间】:2013-06-26 21:34:40
【问题描述】:
示例场景是: 从登录屏幕-主屏幕-然后当我单击隐藏按钮时,应用程序将转到主屏幕,当我再次单击应用程序时,将调用主屏幕
【问题讨论】:
示例场景是: 从登录屏幕-主屏幕-然后当我单击隐藏按钮时,应用程序将转到主屏幕,当我再次单击应用程序时,将调用主屏幕
【问题讨论】:
当你想显示主屏幕时触发一个意图
Intent setIntent = new Intent(Intent.ACTION_MAIN);
setIntent.addCategory(Intent.CATEGORY_HOME);
setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(setIntent);
所以这将在按下隐藏按钮时触发
【讨论】:
我认为你可以使用你可以使用 FLAG_ACTIVITY_CLEAR_TOP
FirstActivity is the first activity in the application:
public static void home(Context ctx) {
if (!(ctx instanceof FirstActivity)) {
Intent intent = new Intent(ctx, FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
ctx.startActivity(intent);
}
}
And If you want to exit from the whole application,this help you in that.
public static void clearAndExit(Context ctx) {
if (!(ctx instanceof FirstActivity)) {
Intent intent = new Intent(ctx, FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle = new Bundle();
bundle.putBoolean("exit", true);
intent.putExtras(bundle);
ctx.startActivity(intent);
} else {
((Activity) ctx).finish();
}
}
i Really Hope this helps.
【讨论】: