0

In my application i want to maintain data without using the local DB even if the application closes. For this i created one class in my app, in that i created static variables so we can access them anywhere in the app. But here some times data is gone i don't know why it's happen. this process is good or any better is there? Somewhere i read that Shared Preferences is useful but i don't know about that.please can anyone share your ideas.

public class AJ_Constant {

    //New Food Item
    public static String strEntrySavedFoodItem = "";
    public static String strReportsSavedFoodItem = "";
    public static ArrayList<String> arrFoodItems = new ArrayList<String>();
}

public class ReportsContentActivity extends Activity {



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View contentView = LayoutInflater.from(getParent()).inflate(R.layout.reports_content, null);  
        setContentView(contentView); 
       AJ_Constant.arrFoodItems.add("Sample");      }}

thanks

naresh
  • 10,332
  • 25
  • 81
  • 124

2 Answers2

0

Visit http://android-er.blogspot.in/2011/01/example-of-using-sharedpreferencesedito.html you can save your data by creating shared preferences.

sarabhai05
  • 578
  • 1
  • 4
  • 12
0

you can have a look here. there are samples how to use SharedPreferences

Community
  • 1
  • 1
Casabian
  • 308
  • 2
  • 8
  • is it good process to maintain the data? Why my data is gone? – naresh Sep 28 '12 at 07:23
  • as far as I know this is the standard way to maintain data in android – Casabian Sep 28 '12 at 07:24
  • you can visit [android dev](http://developer.android.com/guide/topics/data/data-storage.html#pref) there are some additional possibilities how to store data – Casabian Sep 28 '12 at 07:29
  • sharedprefs is key value based so you could use an id for your listitems but i think it's better to write the content of your arraylist to a file separated by a delimiter – Casabian Sep 28 '12 at 07:40