Hi Friends I want to pass an array from one Activity to another Activity,for example pass arrat frin image_view Activity to Blackimage Activity how will i pass please give solution to this problem in android
Read up on making a singleton class, then you can call singleton.setArray(myArray) in one Activity, and singleton.getArray() in the next.
Using a Singleton is probably a bad idea here, especially given Android's kill-happy lifecycle and the high likelihood of leaking Context if you do it wrong. Android has a very simple and powerful built-in message-passing capability on Intents - use it! You should pass the array as an Extra on the Intent, either using the built-in putExtra methods that take Arrays of various Java builtins, or by making sure your array is made of Serializable objects and passing it to the Intent's putExtra method that takes any serializable object. Then you can simply get the extra out of the Intent in the second Activity's onCreate(), no messy singletons necessary.
In addition to the singleton class, you might want to look at using the Android SharedPreferences to save/get any data to either save your settings or prevent loss of data if interrupted.
Also adding android:configChanges="keyboardHidden|orientation"> into the AndroidManifest will prevent your app from losing data if you rotate screens/slide open keyboard.
SharedPref Example
String m_myData[];
Boolean m_myBoolData[];
public static void saveSettings()
{
SharedPreferences.Editor editor = m_SharedPreferences.edit();
for(int ix = 0; ix < m_myData[].length; ix++
{
editor.putString("myKey" + ix, m_myData[ix]);
editor.putBoolean("myKey" + ix, m_myBoolData[ix])
}
}
public static void getSettings()
{
for(int ix = 0; ix < m_myData[].length; ix++
{
m_myData[ix] = m_SharedPreferences.getString("myKey" + ix, false);
m_myBoolData[ix] = m_SharedPreferences.getBoolean("myKey" + ix, false )
}
}