如何在不启动的情况下将数组列表从一个活动传递到另一个活动 [英] How to pass an array list from one activity to another without starting it
问题描述
我有一个包含数组列表的活动
I have an activity which has an array list
ArrayList<String> array = new ArrayList<String>();
我希望在单击保存"按钮时将此数组列表传递给另一个活动,但我不希望该活动开始...
i want this array list to be passed to another activity when a Save button is clicked, but i don't want that activity to start...
通常此代码有助于启动活动
Usually this code helps in starting an activity
public void onClick(View v) {
if (v==Save)
{
Bundle bundle = new Bundle();
bundle.putStringArrayList("DONE", activeURL);
Intent myIntent = new Intent(Reader2.this, Aggregator.class);
myIntent.putExtra("reader2", activeURL);
startActivity(intent);
}
}
但我只想传递数组并开始另一个活动.你能帮我么 ?提前致谢.
but i just want to pass the array and start another activity. Can you please help me ? Thanks in advance.
推荐答案
您可以像这样将 ArrayList 声明为静态的,
You can declare you ArrayList as a static one like this,
public static ArrayList<String> array = new ArrayList<String>();
通过这样做,您可以通过以下方式从任何地方访问您的 ArrayList
By doing this you can access your ArrayList from anywhere by
activity_name.array;
其中 activity_name 是您在其中声明静态 ArrayList 的活动或类
where activity_name is the activity or class in which you declare the static ArrayList
这篇关于如何在不启动的情况下将数组列表从一个活动传递到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!