【发布时间】:2013-12-30 17:20:27
【问题描述】:
我创建了一个主屏幕启动器风格的应用程序:启动主屏幕活动时,会启动一个计时器,结束时我希望显示不同的布局,告诉您“您已超时!请稍候在玩更多游戏前 x 分钟!”
通过在一个 Activity 中多次使用 setContentView() 方法,我已经实现了这一点,但是代码变得混乱且非常不稳定。将 Timed Out 屏幕与完全不同的 Activity 相关联会好得多。这样做的问题是,如果您超时,您只需按主页按钮即可跳过超时并返回主屏幕。
下面是我用来设置主屏幕活动的代码:
ComponentName secComponent = new ComponentName(HomeScreen.class.getPackage().getName(), HomeScreen.class.getName());
mPackageManager.setComponentEnabledSetting(secComponent, Constants.mPackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
因此,在上述情况下,HomeScreen.class 将被设置为主屏幕活动,但由于我的应用正在替换主屏幕,是否有一种简单的方法可以从 HomeScreen.class 切换到我的其他活动应用程序而无需请求用户许可(在这种情况下,您可以解除超时)?
【问题讨论】:
标签: android homescreen