java - What's the closest equivalent to a Session / Cookie variable in Android? -


For example, I want my users to click the "Get a new quote" button, which is a new line To start collecting the database for the data, but I am not sure how to store independent (or cross-activity) data in the activity, such as the line's _id, for which I have new data available Required and updated line Defense will be the name of the system after the activities are done and how to do it?

How do I perform actions / services within a single application?

It depends on the type of data you want to share:

Primitive data types Share primitive data between, use Intent.putExtras (). To pass primitive data that is required to continue to use the storage system

Non-Permanent Object To share complex non-continuous user-defined objects for a short period, the following methods are recommended:

android.app.Application class

The Android.AP application is the base class for those who need to maintain the global application status. It can be accessed through any activity or service through getApplication (). There are some life-cycle methods in it and if Android is automatically installed on your Android manifest If registered in XML, then it will be used immediately.

Public static field / method

An alternative way to make data accessible to activities / services is to use public stable fields and / or methods. You can access these stable fields from any other class in your application. To share an object, the object that creates sets a constant field to point to the object and any other activity that uses this object accesses this static field.

For a Hashmap object of WeakReferences

You can use a Hashmap of the Week context for objects with the Rakhi key. When an activity wants to pass an object in another activity, then it puts the object on the map and the sender sends the key to the key (which is a unique long based on a counter or time stamp) through the addition of intent. The receiver's activity retrieves the object using this key.

A single class

There are advantages to using a stable singleton, such as you can refer to them to obtain an application-specific class Without receiving the application (), or all your applications are going to the problem of hanging an interface on sub-sections so that your different modules can refer to that interface.

However, the control of the life cycle of a stable is not under your control; To comply with the life-cycle model, the application class has an application class of In-static Objects for Inquiry () and On-Cranate () Methods

Continuous Objects It seems to keep going, even then the system can choose to kill its process and start it again later. If you have a data that you need to continue from an activity charge to the next, then you need to represent that data as the state that, when saved by an activity, is informed that it will be removed It is possible.

Complicated persistent user-defined objects to share, the following methods are recommended:

  Application priority files content provider SQLite DB  

If the shared data should be placed at all points where the process of application can be killed, then place the position of stability on the location like application preferences, SQLite DB, file or content provider. Please see data collection for more information on how to use these components.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -