0

I have an Inspection Form for an Android tablet that has 5 activity pages and approximately 30 button clicks. Each button click generates a TextView value which are then compiled at the end of the application to create a report.

My issue is this: is there any other way to maintain state between activities and to carry the data from all the activities to the report stage WITHOUT using Intent and Bundles.

I have read everything thing I can about Intent and Bundles and it seems to be an awkward way of doing things. Being a C++ programmer I am use to addresses and pointers to reach out and get any data value I want, even in some cases using global pointers to maintain state.

Having 30 buttons to create 30 Bundle variables (to which then need to be retrieve by a switch statement) seems overkill when you already have a button ID and a value saved to in a memory address in the application.

Any suggestions?

Regards,

Bob

  • okay.. as a new member it is too early to answer own question. I found this: Maintaining global Application state using the APPLICATION CLASS. Found a good article here: http://www.helloandroid.com/tutorials/maintaining-global-application-state. – user1502634 Jul 05 '12 at 00:50

1 Answers1

0

You don't need to extend the Application class. You can just declare your own class with static (class) variables. Like this:

public class Globals {
    public static String text1;
    public static String text2;
    ...
}

You can access these variables from anywhere in your code, like this:

Globals.text1 = "stuff";

or

String text1 = Globals.text1;
David Wasser
  • 93,459
  • 16
  • 209
  • 274