Is it possible in the main Activity in a separate thread, loading a ArrayList (reading records from a database) and use that ArrayList loaded in a secondary Activity?
Asked
Active
Viewed 208 times
4 Answers
2
You can try new Intent().putStringArrayListExtra(String name, ArrayList<String> value)
to pass String Arraylist from one Activity to another Activity For Refrence See
pass arraylist from one activity to other
0
If you just want to load the data in the Activity and not show views in both Activities then you should use the class "Service" which is an activity running in the background.

Tobias
- 873
- 9
- 17
-
How exactly would you use the class Service? – Waynn Lue Mar 19 '12 at 09:37
-
I would create an interface for the communication between the Service and the Activity that have a function for initiating the fetch and one for registering a handle/callback so that the result can be "returned" to the Activity. http://developer.android.com/reference/android/app/Service.html#LocalServiceSample – Tobias Mar 19 '12 at 10:09
0
You can definitely use your ArrayList in another activity by declaring it as public static.
public static ArrayList<> mylist; // declaration
To use it another activity :-
FirstActivity.mylist......
Hope this will help.

Prem
- 1,664
- 3
- 15
- 20
0
Yes ,it is possible.. but to use in second activity.. the arraylist must not be empty by the time you use it in second class..

5hssba
- 8,079
- 2
- 33
- 35