1

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?

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

How exactly would you use the class Service?
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. developer.android.com/reference/android/app/…
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.

Comments

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..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.