"Add to favorites" option in a soundboard app
<p>I have this code for my soundboard, </p>

<p>public class soundboardActivity extends Activity {</p>

<pre><code>View lastClickedView;

    public static void setIntArrayPref(Context context, String key, ArrayList&lt;Integer&gt;       values) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    JSONArray a = new JSONArray();
    for (int i = 0; i &lt; values.size(); i++) {
        a.put(values.get(i));
    }
    if (!values.isEmpty()) {

        editor.putString(key, a.toString());
    } else {
        editor.putString(key, null);
    }
    editor.commit();
}



   public boolean onCreateOptionsMenu(Menu menu) {
       MenuInflater inflater = getMenuInflater();
       inflater.inflate(R.menu.menu, menu);
       return true;
   }
   // Contextual Menu
    public void onCreateContextMenu(ContextMenu menu, View v,  ContextMenuInfo menuInfo)
    {
        super.onCreateContextMenu(menu, v, menuInfo);

            menu.setHeaderTitle("OPTIONS");
            MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.menu_contex_apm, menu);

                lastClickedView = v;
    }
    public boolean onContextItemSelected(MenuItem item) {

            switch (item.getItemId()) {
                case R.id.ctxtapm_opcio1:
                    //favorites

                    switch (lastClickedView.getId()){
                                 case R.id.a1: favorites.add(R.raw.sound1);
                                return true;
                                    }
                                 case R.id.a2: favorites.add(R.raw.sound2);
                                return true;
                                    }
                                 case R.id.a3: favorites.add(R.raw.sound3);
                                return true;
                                    }
                  setIntArrayPref(this, "favoritos", favorites);


                    return true;
                case R.id.ctxtapm_opcio2:
                   //share

                    return true;

                default:
                    return super.onContextItemSelected(item);
            }
        }

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.apm);

    Map&lt;Integer, Integer&gt; map = new HashMap&lt;Integer, Integer&gt;();
    map.put(R.id.a1, R.raw.sound1);
    map.put(R.id.a2, R.raw.sound2);
    map.put(R.id.a3, R.raw.sound3);



    for (Map.Entry&lt;Integer, Integer&gt; entry : map.entrySet()) {


        final MediaPlayer sound = MediaPlayer.create(this,entry.getValue());
        Button button = (Button) findViewById(entry.getKey());

        registerForContextMenu(button);

        button.setOnClickListener(new View.OnClickListener() {

           public void onClick(View v) {
                sound.start();
            }

        });

    }
</code></pre>

<p>FavoritesActivity code:</p>

<pre><code>   public class FavoritosActivity extends Activity {

ArrayList&lt;Integer&gt; favorites=new ArrayList&lt;Integer&gt;();

public View getView (int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = this.getLayoutInflater();
        View item = inflater.inflate(R.layout.buttonsample, null);

    return item;  
}

public static ArrayList&lt;Integer&gt; getIntArrayPref(Context context, String key) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String json = prefs.getString(key, null);
    ArrayList&lt;Integer&gt; favoritos = new ArrayList&lt;Integer&gt;();
    if (json != null) {
        try {
            JSONArray a = new JSONArray(json);
            for (int i = 0; i &lt; a.length(); i++) {
                int musicaid = a.optInt(i);
                favoritos.add(musicaid);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return favoritos;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.proba);

    favorites = getIntArrayPref(this, "favoritos");

    ListView lv = (ListView) findViewById(R.id.listView1);


    ArrayAdapter&lt;Integer&gt; arrayAdapter =  new ArrayAdapter&lt;Integer&gt;(this,android.R.layout.simple_list_item_1, favorites);
    lv.setAdapter(arrayAdapter); 


}
</code></pre>

<p>}</p>

<p>question is, how can I implement an "add to favorites" option ( favorites are in another activity)  for the contextual menu?</p>

<p>thanks a lot!</p>
