Question

I've created a Home Screen launcher style app: when the Home Screen activity is launched, a timer is initiated at the end of which I want a different layout to show up telling you that "You have timed out! Please wait x minutes before playing more games!"

I've achieved this to some end by utilizing setContentView() method multiple times within one Activity, however the code becomes cluttered and pretty unstable. It would be much better to associate the Timed Out screen with a completely different Activity. The problem with this is that if you time out, you can just press the Home button to skip the time out and go back to the Home Screen.

Below is the code I used to set the Home Screen 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);

So in the case of the above, HomeScreen.class will be set as the Home Screen activity, but since my app is replacing the Home Screen, is there an easy way to switch from HomeScreen.class to a different Activity within my app without having to request user permission (in which case you'd be able to dismiss the Time Out)?

Was it helpful?

Solution

It looks like the only way to switch between such things is to have a singular activity and carefully utilize setContentView() multiple times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top