ADIT
ADIT

Reputation: 2428

How to preserve Object data without passing between activities within Android?

Actually,my application flow is like this Home->A->B->Info(form data)->D->Final page.From final page if I press on one button it again navigates back to A page and start the flow from onwards.If I comes to info page I should display the earliear data.Right now my approach is passing parcelable object within all acitivities from A->B->Info->D->Final.If suppose want to use Preferences, doesn't supports the parcelable object and don't want to put each string of object individually within preferences becaus I had more than 10 items within object.Is there any better approach without passing bundle between actvities.

BR, Developer.

Upvotes: 0

Views: 186

Answers (3)

Parag Chauhan
Parag Chauhan

Reputation: 35956

you can create Global class and declare Static variables and use them in anyware in the application. Example:

public class global_variable {
    public static  String sample ;
}

where you want to use ;

global_variable.sample = "your value";

Upvotes: 2

Alexander
Alexander

Reputation: 48272

If you create a class representing your 'object' with appropriate setters/getters and let that class implement Parceable and then pass that class between Activites as a Parceable in a Bundle, would that be bad?

If that would be bad (e.g. if the amount of object data is very big or they are somehow not Parceable in principle) and you only have one meaningful instance of a class at a time you can make that class a singleton or keep it within your Application object.

Upvotes: -1

Damian
Damian

Reputation: 8072

You could use any number of technologies to parse your data object into a string and reassemble again. Then you could store the string in preferences.

Take a look at gson to convert objects to json http://code.google.com/p/google-gson/ Or you could google xstream to convert to xml

Upvotes: 0

Related Questions