0

I'm making an android application for my school project. This is my first project for android application. I want to know how to make an object that easily accessible by activities or dialog fragment. Should I use put Extra or static class object? or is there alternate way to do that?

public class Location
{
    private string _name;
    private string _address;
    private string _description;
    private List<Storage> _storages { get; set; }
    private int _id;

    public int Id
    {
        get { return _id; }
        set { _id = value; }
    }

    public string Description
    {
        get { return _description; }
        set { _description = value; }
    }
    public string Address
    {
        get { return _address; }
        set { _address = value; }
    }
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    public Location()
    {
        _storages = new List<Storage>();
    }
    public Location(string name, string address,string description)
    {
        Id =Id+1;
        Name = name;
        Address = address;
        Description = description;
        _storages = new List<Storage>();

    }

}

In this code, I'm trying to save all the data that I get from web service. So I don't have to sync from web service every time I open activity.

Hope there is a way.. Thanks in advance :)

Yeremia Danang
  • 139
  • 1
  • 2
  • 12

1 Answers1

0

That depends upon your requirement. If you want your data to be retained till app is running you can use Singleton approach.

If you want persistent storage then there are two normal cases

  1. if you have small amount of data then you can use SharedPreferences
  2. For large amount of data you can use sqllite.

Below are the links of how to use the above stated tech in C#

  • For singleton Approach see this

  • For accessing SharedPreferences see this

  • For accessing Sqllite use see this

Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89