Reputation: 1
I am trying to create an Activity that provides a screen to select icons. After this selection, this app should work as follow:
1- Each selected icon should appear in the home screen, with its own image. These icons should not be available as apps in the application catalog. They should behave as simple shortcuts, added or removed directly by the main activity;
2 - When I press on one of these icons on the home screen, I want to launch a Activity that should have specific behavior, based on which icon was pressed.
Is it possible to implement this requirements? Can you help me with some guidelines or workarounds to solve this?
Thank you very much for your support.
José Reviralho
Upvotes: 0
Views: 344
Reputation: 1006674
Each selected icon should appear in the home screen, with its own image
I am assuming that "its own image" == "selected icon".
You cannot change the icon associated with an activity at runtime. If the roster of icons is reasonably small, and they are all drawable resources, you could try having one <activity-alias>
per icon, all disabled by default, then use PackageManager
and setComponentEnabledSetting()
to enable one the user chooses. If the user can choose the same icon more than once, you would need to have N <activity-alias>
elements per icon (so the app can show up in the launcher for each selection). This can get very wordy very quickly.
They should behave as simple shortcuts, added or removed directly by the main activity
If by "simple shortcuts" you mean "icons in the launcher/app drawer", the <activity-alias>
elements would each have the standard MAIN
/LAUNCHER
<intent-filter>
, so the ones you enable will show up there.
Note, though, that not all home screen implementations will detect when you enable and disable these things, so users may need to reboot if the icons are not showing up.
When I press on one of these icons on the home screen, I want to launch a Activity that should have specific behavior, based on which icon was pressed
You cannot change what activity an <activity-alias>
points to at runtime -- that is hard-coded into the manifest. Either:
You will use one activity for all icons, with different fragments for each distinct icon, or
You will need to have the <activity-alias>
elements all point to one activity that uses Theme.NoDisplay
, which in turn can determine the right real activity to start up, or
You will need M <activity-alias>
elements per icon, one per possible activity, so that you enable the right one for the right icon/activity combination
Is it possible to implement this requirements?
In summary, this will not be easy to implement, though in theory it should be possible.
Upvotes: 1