Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

As we can send String type to another activity like this

public static final String EXTRA_MESSAGE = 
               "com.example.android.twoactivities.extra.MESSAGE";

what should be the code for this

private static final ArrayAdapter LIST_OF_CUSTOMERS = 

P.S.- I am writing this code in MainActivity and want to send Database in the form of ListView to another activity named saveScreen

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
97 views
Welcome To Ask or Share your Answers For Others

1 Answer

My first suggestion would be why cant the second activity simply query the database itself?

Other then that if you must I'd suggest getting the results from the ArrayAdapter into an ArrayList and using Bundle.putParcelableArrayList when calling the second activity.

See here or this for passing Bundles to Activities and reading their values back again, but essentially you would do something like this when calling the second activity:

Intent intent = new Intent(this, SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("LIST_OF_CUSTOMERS", arrayListOfCustomers);
intent.putExtras(bundle);
startActivity(intent);

And inside the second Activity:

ArrayList<..> customers = getActivity().getIntent().getParcelableArrayListExtra<..>("LIST_OF_CUSTOMERS");
if (customers != null) {
    // do something with the data
}

The only thing to remember is that whatever type your list is of i.e. ArrayList<Customer>, Customer class needs to implement the Parcelable interface. See here or here for more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...