Writing to the Manifest.xml during runtime
<p>I have created a project as a Library, the library is setting up an <code>ActionBarSherlock</code> with a <code>SlideMenu</code>. Inside this <code>Slidemenu</code> i have a <code>ListView</code>. When the user presses one of this items inside this <code>ListView</code> a new <code>Activity</code> is supposed to start. My ListView has an adapter like this one:</p>

<pre><code>public class MenuAdapter extends BaseAdapter {

    Context context;
    Activity act;
    ArrayList&lt;SlideMenuItem&gt; menuItemList;

    public MenuAdapter(Activity act, int workflowMenu) {
        this.act = act;
        this.context = act.getApplicationContext();
        parseXml(workflowMenu);
    }

    @Override
    public int getCount() {
        return menuItemList.size();
    }

    @Override
    public Object getItem(int position) {
        return menuItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        if (rowView == null) {
            LayoutInflater inflater = act.getLayoutInflater();
            rowView = inflater.inflate(R.layout.slidemenu_listitem, null);
            MenuItemHolder viewHolder = new MenuItemHolder();
            viewHolder.label = (TextView) rowView.findViewById(R.id.menuLabel);
            viewHolder.icon = (ImageView) rowView.findViewById(R.id.menu_icon);
            rowView.setTag(viewHolder);
        }

        MenuItemHolder holder = (MenuItemHolder) rowView.getTag();
        String s = menuItemList.get(position).label;
        holder.label.setText(s);
        holder.icon.setImageDrawable(menuItemList.get(position).icon);

        rowView.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                SlideMenuItem item = (SlideMenuItem) getItem(position);
                Toast.makeText(context, "Id: " + Integer.toString(item.id), Toast.LENGTH_SHORT).show(); 

            }
        });

        return rowView;
    }

    public class SlideMenuItem {
        public int id;
        public Drawable icon;
        public String label;
    }

    class MenuItemHolder {
        public TextView label;
        public ImageView icon;
    }

    private void parseXml(int menu) {

        menuItemList = new ArrayList&lt;SlideMenuItem&gt;();

        try {
            XmlResourceParser xpp = context.getResources().getXml(menu);

            xpp.next();
            int eventType = xpp.getEventType();

            while (eventType != XmlPullParser.END_DOCUMENT) {

                if (eventType == XmlPullParser.START_TAG) {

                    String elemName = xpp.getName();

                    if (elemName.equals("item")) {

                        String textId = xpp.getAttributeValue(
                                "http://schemas.android.com/apk/res/android",
                                "title");
                        String iconId = xpp.getAttributeValue(
                                "http://schemas.android.com/apk/res/android",
                                "icon");
                        String resId = xpp.getAttributeValue(
                                "http://schemas.android.com/apk/res/android",
                                "id");

                        SlideMenuItem item = new SlideMenuItem();
                        item.id = Integer.valueOf(resId.replace("@", ""));
                        item.icon = context.getResources().getDrawable(
                                Integer.valueOf(iconId.replace("@", "")));
                        item.label = resourceIdToString(textId);

                        menuItemList.add(item);

                        Log.v("ADDED ITEM LABEL: ", item.label); //This triggers with the right labels, so the listview does exist!
                    }

                }

                eventType = xpp.next();

            }
            Log.v("MenuList: ", "Size: " + Integer.toString(menuItemList.size()));
            for(SlideMenuItem item : menuItemList) {
                Log.v("MenuList: ", Integer.toString(item.id) + ": " + item.label);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private String resourceIdToString(String text) {
        if (!text.contains("@")) {
            return text;
        } else {
            String id = text.replace("@", "");
            return context.getResources().getString(Integer.valueOf(id));

        }
    }
}
</code></pre>

<p>The workflowMenu parameter is a xml file holding the menu items, so the listview can be populated:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt;

    &lt;item
        android:id="@+id/item_one"
        android:icon="@drawable/ic_launcher"
        android:title="Item 1"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/item_two"
        android:icon="@drawable/ic_launcher"
        android:title="Item 2"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/item_three"
        android:icon="@drawable/ic_launcher"
        android:title="Item 3"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/item_four"
        android:icon="@drawable/ic_launcher"
        android:title="Item 4"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/item_five"
        android:icon="@drawable/ic_launcher"
        android:title="Item 5"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/item_seven"
        android:icon="@drawable/ic_launcher"
        android:title="Item 6"&gt;
    &lt;/item&gt;
    &lt;item
        android:id="@+id/item_six"
        android:icon="@drawable/ic_launcher"
        android:title="Item 7"&gt;
    &lt;/item&gt;
&lt;/menu&gt;
</code></pre>

<p>From my MainProject, the library is called like this:</p>

<pre><code>public class MainActivity extends BaseWindow {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.InitializeWindow(MainActivity.this, R.layout.activity_main, R.menu.slide_menu, "Home"); 


    }
</code></pre>

<p>Where <code>BaseWindow</code> will setup all the neccessary GUI. The problem occurs when I want to start a new Activity, when the user presses one item in the listView in my library. </p>

<p>if the <code>listview</code> was constructed in the same project as the I could just specify the Activities in one <code>Manifest</code> file and start the activity inside the adapter like this:</p>

<pre><code>rowView.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                launchActivity(position);
            }

        });

public void launchActivity(int position) {

    Class&lt;?&gt; cls = null;
    switch (menuItemList.get(position).id) {
        case R.id.item_one:
            cls = FirstClass.class;
            act.finish();
            break;
    }
    Intent intent = new Intent(context, cls);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
</code></pre>

<p>But since the adapter is in another project(the library) I also have to declare the activities in the library manifest. I cant see how I should do so, if I dont know the name of this activity. And I guess there is no way to write to the manifest or create activity declaration during runtime due to security reasons. </p>

<p>Does anybody know what am trying to achieve here? Please give me some suggestions on how I can solve this. </p>

<p>Please just ask if something is unclear. </p>

<p>Thanks!</p>
