Question about android default to communicate with other Activitys

Asked

Viewed 56 times

0

I have an Activitymain, it starts at the beginning and only ends its activity at the end of the application, that is while browsing other activitys of the app this Activity will always be behind. My question is, at Activitymain I can own one:

public Static Arrailist< Object > list;

And at runtime when I’m browsing another app’s app, I can work with the Activitymain list by adding items, or filling in Listview, or etc?

example:

Activitymain.lista.add(item)

This has already tested and works. But the question is whether it is correct to program this way? For, if I were not to do this, I would need to pass the arrayList through intents every time I call a new Activity.

  • The ideal was to have everything in Database. And add directly to Database. That way is fine, if you make sure Activitymain NEVER ends before time.

  • In my project I have a local base that stores only the items of the arrayList, and Activitymain is responsible for taking these items and creating an Arraylist with them, I thought already, but it would not be costly all Activitymain make communication with the BD?

  • It would be more expensive, but nothing that you notice a lot (depending on the size of the list) but it was guaranteed not to lose information. That’s why depends on, gives importance of not losing data and the importance of having the fastest application.

  • I’m in doubt if I can implement this way or would it be gambiarra for not passing through Intent.

  • So there is a risk that the array will not be found with the data?

  • There is the risk of your Activitymain giving problems and the array go to life.

  • 1

    My suggestion is to migrate this list to the scope of the Application instance non-static, since it is guaranteed to be "active" while the application is running. In this reply (http://answall.com/questions/40666/erro-ao-tentarysearchdata/40673#40673) I comment on how to configure a. Note: I still think the idea of @Jorgeb. about migrating this data to Sqlite is the best, but it depends on your context.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.