In Android Studio (using java) for app development, I would pass String values or arrayList values from one view to another using intents. For example, I would write:
Intent myIntent = new Intent(Activity1.this, Activity2.class);
String thisString = “PassOnThisString”;
startActivity(myIntent); //(or startActivityforResult(myIntent, 1000)
On the second view, I would write:
Intent intent = getIntent();
String importantString = intent.getExtra(“ExtraCode”);
One of my goals is to be select several rows from a “MenuItem” DataGrid and upon selection, add those items to a “CustomorCart” data model in the form of relationships. Is this possible?
Thank you for your help!
There are a number of ways to achieve this:
- When switching views you can pass some custom data. If you all you need to pass is a set of simple key/value-pairs this is the easiest. You would do:
context.setView(<view-name>, [record or record-id], [query-data]);
Here record (or record-id) is the record you want to pass to the new view (which will be used to populate its primary form - this is a method that can be used too - if you are building up a structure that originates from a common model - e.g. to populate some data in one view and then pass it on to another and add on to it). The query-data however is a plain JSON-object with key/value pairs that you can pass and use for whatever purposes you may have (note that the values must be primitives).
- You can persist data. You mention this is for a shopping cart. You can store the shopping-cart contents using
context.setData(<key>, <value>, [scope]). Key and value I guess need no explanation but scope can either be left out (which means the scope is just the current view) or one of:
- global - data is available throughout the app but will not be persisted (i.e. lost if the app is restarted).
- persistent - data is persisted and will survive app-restarts.
To retrieve data you use
Hope this helps!
Great! Thank you, Johan! I’ll give that a shot.