Associate activity with database ID

Posted by Mohit Deshpande on Stack Overflow See other posts from Stack Overflow or by Mohit Deshpande
Published on 2012-06-17T19:23:01Z Indexed on 2012/06/17 21:16 UTC
Read the original article Hit count: 149

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about android