I have one activity called mylikes , it can be called from main activity then it should display the liked items list. Another activity called programs have list of items where i press the like button and it should add that item to liked item list and display in Mylike activity.
I am adding that item to array in program activity but when i call the mylike activity from main, i am getting force close error.So how to make array list global.
I have one activity called mylikes , it can be called from main activity
Share
You can override the default application class with your own and create and use your array from there. If you have an application called MyApplication then add a class
For adding the data to array use :
You can then access in an activity via something like
In your application manifest you also need to name your extended application class by adding the name to your application block
If you have a globally scoped complex object that all activities need to access and you don’t want to serialize/deserialize that’s the easiest way IMO, for simpler scenarios you can pass items when you start the activity by putting extra’s into the intent
You can also use singletons, but the application class is pretty easy to manage
I did not test or compile code, this is just intended as an overview so watch out for typos etc.
Here is the link for the Application class doc’s Application