I have this application with 2 classes, in the first class I define a list array wich I want to access in my second class, how do I do that? class one (with the array extends listActivity and the other class extends Activity). I don't think it's nessecary to post my code as I believe there is a quick solution to this I just don't know it. Allthough I can post it if you can't help me without seeing the actual code.
            Asked
            
        
        
            Active
            
        
            Viewed 105 times
        
    0
            
            
         
    
    
        Alex Lockwood
        
- 83,063
- 39
- 206
- 250
 
    
    
        jlodenius
        
- 829
- 2
- 13
- 24
- 
                    1http://androidideasblog.blogspot.in/2010/02/passing-list-of-objects-between.html – Samir Mangroliya Mar 22 '12 at 18:06
- 
                    Seems to me like these examples all require me to make a class that implements parcelable? but I need to send my entire array from a listactivity class to an activity class, don't find anything here that works.. :( – jlodenius Mar 22 '12 at 18:36
2 Answers
1
            
            
        You can use a custom ApplicationContext to share global state between activities - see here for more details...
 
    
    
        Community
        
- 1
- 1
 
    
    
        Paul Drummond
        
- 6,043
- 6
- 30
- 38
0
            you can pass ArrayList<String> 's across activities using intentExtras.
 ArrayList<String> myArrayList = new ArrayList<String>();
 // populate your array  -> if you want to send objects make a string form of them
 Intent myIntent = new Intent(this, Activit2.class);
 mtIntent.putStringArrayList("my_array_list", myArrayList);
In Activity2
Intent intent = getIntent();
 List<String> stringMediaList = intent.getStringArrayListExtra("my_array_list");
for (int i = 0; i < stringMediaList.size(); i++) {
   //reconstruct object if needed
}
this will work if you dont want to use parcelable
 
    
    
        Alex Lockwood
        
- 83,063
- 39
- 206
- 250
 
    
    
        Laith Alnagem
        
- 654
- 6
- 13
- 
                    Thanks alot man! worked great, just a last question though if you see this. How can I pass an int to another class? (no intArray just a regular int) there should be a similar way right? – jlodenius Mar 22 '12 at 20:18
- 
                    Yes, myIntent.putIntegerArrayListExtra("my_integer_array", value) where value is a ArrayList. For regular int's use myIntent.putExtra("my_int" , 9001); – Laith Alnagem Mar 23 '12 at 02:26