Associate activity with database ID
- by Mohit Deshpande
I have a main ListView that is based on an adapter from my database. Each database id is "assigned" to an Activity via the ListView. And in my AndroidManifest, each activity has an intent filter with a custom action. Now with this, I have had to create this class:
public final class ActivityLauncher {
private ActivityLauncher() { }
public static void launch(Context c, int id) {
switch(id) {
case 1:
Intent intent = new Intent();
intent.setAction(SomeActivity.ACTION_SOMEACTIVITY);
c.startActivity(intent);
break;
case 2:
...
break;
...
}
}
private static void st(Context context, String action) {
Intent intent = new Intent();
intent.setAction(action);
context.startActivity(intent);
}
}
So I have to manually create a new case for the switch statement. This would get troublesome if I have to rearrange or delete an id. Is there any way to get around this?